@niledatabase/server 2.5.0-alpha.0 → 3.0.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.
Files changed (52) hide show
  1. package/dist/Server.d.ts +17 -4
  2. package/dist/api/handlers/DELETE.d.ts +3 -0
  3. package/dist/api/handlers/GET.d.ts +3 -0
  4. package/dist/api/handlers/POST.d.ts +3 -0
  5. package/dist/api/handlers/PUT.d.ts +3 -0
  6. package/dist/api/handlers/index.d.ts +8 -0
  7. package/dist/api/routes/auth/callback.d.ts +3 -0
  8. package/dist/api/routes/auth/csrf.d.ts +3 -0
  9. package/dist/api/routes/auth/error.d.ts +3 -0
  10. package/dist/api/routes/auth/index.d.ts +7 -0
  11. package/dist/api/routes/auth/providers.d.ts +3 -0
  12. package/dist/api/routes/auth/session.d.ts +3 -0
  13. package/dist/api/routes/auth/signin.d.ts +33 -0
  14. package/dist/api/routes/auth/signout.d.ts +3 -0
  15. package/dist/api/routes/me/index.d.ts +4 -0
  16. package/dist/api/routes/tenants/GET.d.ts +32 -0
  17. package/dist/api/routes/tenants/POST.d.ts +45 -0
  18. package/dist/api/routes/tenants/[tenantId]/DELETE.d.ts +34 -0
  19. package/dist/api/routes/tenants/[tenantId]/users/GET.d.ts +35 -0
  20. package/dist/api/routes/tenants/[tenantId]/users/POST.d.ts +44 -0
  21. package/dist/api/routes/tenants/[tenantId]/users/PUT.d.ts +30 -0
  22. package/dist/api/routes/tenants/[tenantId]/users/[userId]/DELETE.d.ts +30 -0
  23. package/dist/api/routes/tenants/[tenantId]/users/index.d.ts +4 -0
  24. package/dist/api/routes/tenants/index.d.ts +4 -0
  25. package/dist/api/routes/users/GET.d.ts +34 -0
  26. package/dist/api/routes/users/POST.d.ts +66 -0
  27. package/dist/api/routes/users/[userId]/PUT.d.ts +40 -0
  28. package/dist/api/routes/users/index.d.ts +4 -0
  29. package/dist/api/swagger.d.ts +152 -0
  30. package/dist/api/types.d.ts +18 -0
  31. package/dist/api/utils/auth.d.ts +6 -0
  32. package/dist/api/utils/request.d.ts +3 -0
  33. package/dist/api/utils/routes/apiRoutes.d.ts +14 -0
  34. package/dist/api/utils/routes/defaultRoutes.d.ts +2 -0
  35. package/dist/api/utils/routes/makeRestUrl.d.ts +1 -0
  36. package/dist/api/utils/routes/proxyRoutes.d.ts +12 -0
  37. package/dist/api/utils/routes/urlMatches.d.ts +1 -0
  38. package/dist/auth/index.d.ts +12 -38
  39. package/dist/server.cjs.development.js +2240 -643
  40. package/dist/server.cjs.development.js.map +1 -1
  41. package/dist/server.cjs.production.min.js +1 -1
  42. package/dist/server.cjs.production.min.js.map +1 -1
  43. package/dist/server.esm.js +2240 -643
  44. package/dist/server.esm.js.map +1 -1
  45. package/dist/tenants/index.d.ts +3 -1
  46. package/dist/types.d.ts +9 -0
  47. package/dist/users/index.d.ts +15 -5
  48. package/dist/utils/Config/envVars.d.ts +6 -1
  49. package/dist/utils/Config/index.d.ts +17 -1
  50. package/dist/utils/Requester/index.d.ts +2 -1
  51. package/dist/utils/fetch.d.ts +3 -3
  52. package/package.json +5 -3
package/dist/Server.d.ts CHANGED
@@ -1,14 +1,27 @@
1
1
  import { Pool } from 'pg';
2
2
  import { ServerConfig } from './types';
3
3
  import { Config } from './utils/Config';
4
- import Auth from './auth';
5
4
  import Users from './users';
6
5
  import Tenants from './tenants';
7
- type Api = {
8
- auth: Auth;
6
+ import { Routes } from './api/types';
7
+ declare class Api {
8
+ config: Config;
9
9
  users: Users;
10
10
  tenants: Tenants;
11
- };
11
+ routes: Routes;
12
+ handlers: {
13
+ GET: (req: Request) => Promise<void | Response>;
14
+ POST: (req: Request) => Promise<void | Response>;
15
+ DELETE: (req: Request) => Promise<void | Response>;
16
+ PUT: (req: Request) => Promise<void | Response>;
17
+ };
18
+ constructor(config: Config);
19
+ set headers(headers: Headers);
20
+ login(payload: {
21
+ email: string;
22
+ password: string;
23
+ }): Promise<void>;
24
+ }
12
25
  export declare class Server {
13
26
  config: Config;
14
27
  api: Api;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../types';
2
+ import { Config } from '../../utils/Config';
3
+ export default function DELETER(configRoutes: Routes, config: Config): (req: Request) => Promise<void | Response>;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../types';
2
+ import { Config } from '../../utils/Config';
3
+ export default function GETTER(configRoutes: Routes, config: Config): (req: Request) => Promise<void | Response>;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../types';
2
+ import { Config } from '../../utils/Config';
3
+ export default function POSTER(configRoutes: Routes, config: Config): (req: Request) => Promise<void | Response>;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../types';
2
+ import { Config } from '../../utils/Config';
3
+ export default function PUTER(configRoutes: Routes, config: Config): (req: Request) => Promise<void | Response>;
@@ -0,0 +1,8 @@
1
+ import { Config } from '../../utils/Config';
2
+ import { Routes } from '../types';
3
+ export default function Handlers(configRoutes: Routes, config: Config): {
4
+ GET: (req: Request) => Promise<void | Response>;
5
+ POST: (req: Request) => Promise<void | Response>;
6
+ DELETE: (req: Request) => Promise<void | Response>;
7
+ PUT: (req: Request) => Promise<void | Response>;
8
+ };
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../../types';
2
+ export default function route(request: Request): Promise<Response>;
3
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../../types';
2
+ export default function route(req: Request): Promise<void | Response>;
3
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../../types';
2
+ export default function route(req: Request): Promise<void | Response>;
3
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,7 @@
1
+ export { default as handleSignIn, matches as matchSignIn } from './signin';
2
+ export { default as handleSession, matches as matchSession } from './session';
3
+ export { default as handleProviders, matches as matchProviders, } from './providers';
4
+ export { default as handleCsrf, matches as matchCsrf } from './csrf';
5
+ export { default as handleCallback, matches as matchCallback, } from './callback';
6
+ export { default as handleSignOut, matches as matchSignOut } from './signout';
7
+ export { default as handleError, matches as matchError } from './error';
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../../types';
2
+ export default function route(req: Request): Promise<void | Response>;
3
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../../types';
2
+ export default function route(req: Request): Promise<void | Response>;
3
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @swagger
3
+ * /api/auth/signin:
4
+ * get:
5
+ * tags:
6
+ * - authentication
7
+ * summary: lists users in the tenant
8
+ * description: Returns information about the users within the tenant
9
+ * provided
10
+ * operationId: signin
11
+ * parameters:
12
+ * - name: tenantId
13
+ * in: path
14
+ * required: true
15
+ * schema:
16
+ * type: string
17
+ * responses:
18
+ * "200":
19
+ * description: A list of users
20
+ * content:
21
+ * application/json:
22
+ * schema:
23
+ * $ref: '#/components/schemas/User'
24
+ * "404":
25
+ * description: Not found
26
+ * content: {}
27
+ * "401":
28
+ * description: Unauthorized
29
+ * content: {}
30
+ */
31
+ import { Routes } from '../../types';
32
+ export default function route(request: Request): Promise<void | Response>;
33
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,3 @@
1
+ import { Routes } from '../../types';
2
+ export default function route(request: Request): Promise<void | Response>;
3
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,4 @@
1
+ import { Routes } from '../../types';
2
+ import { Config } from '../../../utils/Config';
3
+ export default function route(request: Request, config: Config): Promise<void | Response>;
4
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,32 @@
1
+ import { ActiveSession } from '../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants:
5
+ * get:
6
+ * tags:
7
+ * - tenants
8
+ * summary: list tenants by user
9
+ * description: Creates a user in the database
10
+ * operationId: listTenants
11
+ * responses:
12
+ * "200":
13
+ * description: a list of tenants
14
+ * content:
15
+ * application/json:
16
+ * schema:
17
+ * type: array
18
+ * items:
19
+ * $ref: "#/components/schemas/Tenant"
20
+ * "400":
21
+ * description: API/Database failures
22
+ * content:
23
+ * text/plain:
24
+ * schema:
25
+ * type: string
26
+ * "401":
27
+ * description: Unauthorized
28
+ * content: {}
29
+ */
30
+ export declare function GET(session: ActiveSession, init: RequestInit & {
31
+ request: Request;
32
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,45 @@
1
+ import { ActiveSession } from '../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants:
5
+ * post:
6
+ * tags:
7
+ * - tenants
8
+ * summary: Create a tenant
9
+ * description: Creates a new tenant in a database.
10
+ * operationId: createTenant
11
+ * requestBody:
12
+ * description: A wrapper for the tenant name.
13
+ * content:
14
+ * application/json:
15
+ * schema:
16
+ * $ref: '#/components/schemas/CreateTenantRequest'
17
+ * examples:
18
+ * Create Tenant Request:
19
+ * summary: Creates a named tenant
20
+ * description: Create Tenant Request
21
+ * value:
22
+ * name: My Sandbox
23
+ * responses:
24
+ * "201":
25
+ * description: Tenant created
26
+ * content:
27
+ * application/json:
28
+ * schema:
29
+ * $ref: '#/components/schemas/Tenant'
30
+ * "401":
31
+ * description: Unauthorized
32
+ * content:
33
+ * application/json:
34
+ * schema:
35
+ * $ref: '#/components/schemas/APIError'
36
+ * "404":
37
+ * description: Database not found
38
+ * content:
39
+ * application/json:
40
+ * schema:
41
+ * $ref: '#/components/schemas/APIError'
42
+ */
43
+ export declare function POST(session: ActiveSession, init: RequestInit & {
44
+ request: Request;
45
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,34 @@
1
+ import { ActiveSession } from '../../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants/{tenantId}:
5
+ * delete:
6
+ * tags:
7
+ * - tenants
8
+ * summary: Deletes a tenant.
9
+ * operationId: deleteTenant
10
+ * parameters:
11
+ * - name: tenantId
12
+ * in: path
13
+ * required: true
14
+ * schema:
15
+ * type: string
16
+ * responses:
17
+ * "204":
18
+ * description: Tenant deleted
19
+ * "401":
20
+ * description: Unauthorized
21
+ * content:
22
+ * application/json:
23
+ * schema:
24
+ * $ref: '#/components/schemas/APIError'
25
+ * "404":
26
+ * description: Tenant not found
27
+ * content:
28
+ * application/json:
29
+ * schema:
30
+ * $ref: '#/components/schemas/APIError'
31
+ */
32
+ export declare function DELETE(session: ActiveSession, init: RequestInit & {
33
+ request: Request;
34
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,35 @@
1
+ import { ActiveSession } from '../../../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants/{tenantId}/users:
5
+ * get:
6
+ * tags:
7
+ * - users
8
+ * summary: List tenant users
9
+ * description: Lists users that are associated with the specified tenant.
10
+ * operationId: listTenantUsers
11
+ * parameters:
12
+ * - name: tenantId
13
+ * in: path
14
+ * required: true
15
+ * schema:
16
+ * type: string
17
+ * responses:
18
+ * "200":
19
+ * description: Users found
20
+ * content:
21
+ * application/json:
22
+ * schema:
23
+ * type: array
24
+ * items:
25
+ * $ref: '#/components/schemas/User'
26
+ * "401":
27
+ * description: Unauthorized
28
+ * content:
29
+ * application/json:
30
+ * schema:
31
+ * $ref: '#/components/schemas/APIError'
32
+ */
33
+ export declare function GET(session: ActiveSession, init: RequestInit & {
34
+ request: Request;
35
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,44 @@
1
+ import { ActiveSession } from '../../../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants/{tenantId}/users:
5
+ * post:
6
+ * tags:
7
+ * - users
8
+ * summary: Create a user in a tenant
9
+ * description: Creates a new user and associates that user with the specified
10
+ * tenant.
11
+ * operationId: createTenantUser
12
+ * parameters:
13
+ * - name: tenantId
14
+ * in: path
15
+ * required: true
16
+ * schema:
17
+ * type: string
18
+ * requestBody:
19
+ * description: |
20
+ * The email and password combination the user will use to authenticate.
21
+ * The `name` is optional; if provided it will be recorded in the `users` table.
22
+ * content:
23
+ * application/json:
24
+ * schema:
25
+ * $ref: '#/components/schemas/CreateBasicUserRequest'
26
+ * examples:
27
+ * Create User Request:
28
+ * summary: Creates a user with basic credentials
29
+ * description: Create User Request
30
+ * value:
31
+ * email: a.user@somedomain.com
32
+ * password: somepassword
33
+ * name: A. User
34
+ * responses:
35
+ * "201":
36
+ * description: User created
37
+ * content:
38
+ * application/json:
39
+ * schema:
40
+ * $ref: '#/components/schemas/User'
41
+ */
42
+ export declare function POST(session: ActiveSession, init: RequestInit & {
43
+ request: Request;
44
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,30 @@
1
+ import { ActiveSession } from '../../../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants/{tenantId}/users:
5
+ * put:
6
+ * tags:
7
+ * - tenants
8
+ * summary: associates an existing user with the tenant
9
+ * operationId: linkUser
10
+ * parameters:
11
+ * - name: tenantId
12
+ * in: path
13
+ * required: true
14
+ * schema:
15
+ * type: string
16
+ * requestBody:
17
+ * description: |
18
+ * The email and password combination the user will use to authenticate.
19
+ * The `name` is optional; if provided it will be recorded in the `users` table.
20
+ * content:
21
+ * application/json:
22
+ * schema:
23
+ * $ref: '#/components/schemas/AssociateUserRequest'
24
+ * responses:
25
+ * "201":
26
+ * description: add user to tenant
27
+ */
28
+ export declare function PUT(session: ActiveSession, init: RequestInit & {
29
+ request: Request;
30
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,30 @@
1
+ import { ActiveSession } from '../../../../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/tenants/{tenantId}/users/{userId}:
5
+ * delete:
6
+ * tags:
7
+ * - tenants
8
+ * summary: removes a user from a tenant
9
+ * description: removes an associated user from a specified
10
+ * tenant.
11
+ * operationId: unlinkUser
12
+ * parameters:
13
+ * - name: tenantId
14
+ * in: path
15
+ * required: true
16
+ * schema:
17
+ * type: string
18
+ * - name: userId
19
+ * in: path
20
+ * required: true
21
+ * schema:
22
+ * type: string
23
+
24
+ * responses:
25
+ * "204":
26
+ * description: User removed
27
+ */
28
+ export declare function DELETE(session: ActiveSession, init: RequestInit & {
29
+ request: Request;
30
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,4 @@
1
+ import { Config } from '../../../../../utils/Config';
2
+ import { Routes } from '../../../../types';
3
+ export default function route(request: Request, config: Config): Promise<void | Response>;
4
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,4 @@
1
+ import { Config } from '../../../utils/Config';
2
+ import { Routes } from '../../types';
3
+ export default function route(request: Request, config: Config): Promise<void | Response>;
4
+ export declare function matches(configRoutes: Routes, request: Request): boolean;
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @swagger
3
+ * /api/users:
4
+ * get:
5
+ * tags:
6
+ * - users
7
+ * summary: lists users in the tenant
8
+ * description: Returns information about the users within the tenant
9
+ * provided. You can also pass the a `niledb-tenantId` in the header or in a cookie.
10
+ * operationId: listUsers
11
+ * parameters:
12
+ * - name: tenantId
13
+ * in: query
14
+ * schema:
15
+ * type: string
16
+ * responses:
17
+ * "200":
18
+ * description: A list of users
19
+ * content:
20
+ * application/json:
21
+ * schema:
22
+ * type: array
23
+ * items:
24
+ * $ref: '#/components/schemas/TenantUser'
25
+ * "404":
26
+ * description: Not found
27
+ * content: {}
28
+ * "401":
29
+ * description: Unauthorized
30
+ * content: {}
31
+ */
32
+ export declare function GET(init: RequestInit & {
33
+ request: Request;
34
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,66 @@
1
+ import { ActiveSession } from '../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/users:
5
+ * post:
6
+ * tags:
7
+ * - users
8
+ * summary: Creates a user
9
+ * description: Creates a user in the database
10
+ * operationId: createUser
11
+ * parameters:
12
+ * - name: tenantId
13
+ * description: A tenant id to add the user to when they are created
14
+ * in: query
15
+ * schema:
16
+ * type: string
17
+ * - name: newTenantName
18
+ * description: A tenant name to create, then the user to when they are created
19
+ * in: query
20
+ * schema:
21
+ * type: string
22
+ * requestBody:
23
+ * description: |-
24
+ * The email and password combination the user will use to authenticate.
25
+ * The `name` is optional; if provided it will be recorded in the `users` table.
26
+ * The `newTenant` is optional; if provided, it is used as the name of a new tenant record associated with the newly created user.
27
+ * content:
28
+ * application/json:
29
+ * schema:
30
+ * $ref: '#/components/schemas/CreateBasicUserRequest'
31
+ * examples:
32
+ * Create User Request:
33
+ * summary: Creates a user with basic credentials
34
+ * description: Create User Request
35
+ * value:
36
+ * email: a.user@somedomain.com
37
+ * password: somepassword
38
+ * name: A. User
39
+ * Create User Request with Tenant:
40
+ * summary: Creates a user and a new tenant for that user
41
+ * description: Create User Request with Tenant
42
+ * value:
43
+ * email: a.user@somedomain.com
44
+ * password: somepassword
45
+ * name: A. User
46
+ * newTenant: My Sandbox
47
+ * responses:
48
+ * "201":
49
+ * description: User created
50
+ * content:
51
+ * application/json:
52
+ * schema:
53
+ * $ref: "#/components/schemas/User"
54
+ * "400":
55
+ * description: API/Database failures
56
+ * content:
57
+ * text/plain:
58
+ * schema:
59
+ * type: string
60
+ * "401":
61
+ * description: Unauthorized
62
+ * content: {}
63
+ */
64
+ export declare function POST(session: void | ActiveSession, init: RequestInit & {
65
+ request: Request;
66
+ }, log?: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,40 @@
1
+ import { ActiveSession } from '../../../utils/auth';
2
+ /**
3
+ * @swagger
4
+ * /api/users/{userid}:
5
+ * put:
6
+ * tags:
7
+ * - users
8
+ * summary: update a user
9
+ * description: updates a user within the tenant
10
+ * operationId: updateUser
11
+ * parameters:
12
+ * - name: userid
13
+ * in: path
14
+ * required: true
15
+ * schema:
16
+ * type: string
17
+ * requestBody:
18
+ * description: |-
19
+ * Update a user
20
+ * content:
21
+ * application/json:
22
+ * schema:
23
+ * $ref: '#/components/schemas/UpdateUserRequest'
24
+ * responses:
25
+ * "200":
26
+ * description: An updated user
27
+ * content:
28
+ * application/json:
29
+ * schema:
30
+ * $ref: '#/components/schemas/User'
31
+ * "404":
32
+ * description: Not found
33
+ * content: {}
34
+ * "401":
35
+ * description: Unauthorized
36
+ * content: {}
37
+ */
38
+ export declare function PUT(session: void | ActiveSession, init: RequestInit & {
39
+ request: Request;
40
+ }, log: (...args: string[]) => void): Promise<void | Response>;
@@ -0,0 +1,4 @@
1
+ import { Routes } from '../../types';
2
+ import { Config } from '../../../utils/Config';
3
+ export default function route(request: Request, config: Config): Promise<void | Response>;
4
+ export declare function matches(configRoutes: Routes, request: Request): boolean;