@niledatabase/server 3.0.0-alpha.4 → 3.0.0-alpha.40

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 (54) hide show
  1. package/dist/Api.d.ts +25 -0
  2. package/dist/Server.d.ts +2 -25
  3. package/dist/api/routes/auth/callback.d.ts +2 -1
  4. package/dist/api/routes/auth/csrf.d.ts +2 -1
  5. package/dist/api/routes/auth/error.d.ts +2 -1
  6. package/dist/api/routes/auth/index.d.ts +1 -0
  7. package/dist/api/routes/auth/providers.d.ts +2 -1
  8. package/dist/api/routes/auth/signin.d.ts +2 -1
  9. package/dist/api/routes/auth/signout.d.ts +2 -1
  10. package/dist/api/routes/auth/verify-request.d.ts +4 -0
  11. package/dist/api/routes/signup/POST.d.ts +66 -0
  12. package/dist/api/routes/signup/index.d.ts +4 -0
  13. package/dist/api/routes/tenants/GET.d.ts +3 -2
  14. package/dist/api/routes/tenants/POST.d.ts +3 -3
  15. package/dist/api/routes/tenants/[tenantId]/DELETE.d.ts +3 -3
  16. package/dist/api/routes/tenants/[tenantId]/GET.d.ts +37 -0
  17. package/dist/api/routes/tenants/[tenantId]/PUT.d.ts +38 -0
  18. package/dist/api/routes/tenants/[tenantId]/users/GET.d.ts +3 -3
  19. package/dist/api/routes/tenants/[tenantId]/users/POST.d.ts +3 -2
  20. package/dist/api/routes/tenants/[tenantId]/users/PUT.d.ts +3 -3
  21. package/dist/api/routes/tenants/[tenantId]/users/[userId]/DELETE.d.ts +3 -3
  22. package/dist/api/routes/users/GET.d.ts +3 -2
  23. package/dist/api/routes/users/POST.d.ts +3 -3
  24. package/dist/api/routes/users/[userId]/PUT.d.ts +3 -2
  25. package/dist/api/types.d.ts +1 -0
  26. package/dist/api/utils/auth.d.ts +8 -0
  27. package/dist/api/utils/request.d.ts +1 -1
  28. package/dist/api/utils/routes/apiRoutes.d.ts +6 -2
  29. package/dist/api/utils/routes/makeRestUrl.d.ts +2 -1
  30. package/dist/api/utils/routes/proxyRoutes.d.ts +3 -1
  31. package/dist/auth/index.d.ts +10 -1
  32. package/dist/db/DBManager.d.ts +1 -0
  33. package/dist/db/NileInstance.d.ts +1 -1
  34. package/dist/index.d.ts +3 -0
  35. package/dist/server.cjs.development.js +2848 -2055
  36. package/dist/server.cjs.development.js.map +1 -1
  37. package/dist/server.cjs.production.min.js +1 -1
  38. package/dist/server.cjs.production.min.js.map +1 -1
  39. package/dist/server.esm.js +2849 -2057
  40. package/dist/server.esm.js.map +1 -1
  41. package/dist/tenants/index.d.ts +11 -8
  42. package/dist/tenants/types.d.ts +4 -0
  43. package/dist/types.d.ts +9 -0
  44. package/dist/users/index.d.ts +14 -39
  45. package/dist/users/types.d.ts +36 -0
  46. package/dist/utils/Config/envVars.d.ts +5 -5
  47. package/dist/utils/Config/index.d.ts +9 -8
  48. package/dist/utils/Event/index.d.ts +0 -1
  49. package/dist/utils/Logger.d.ts +5 -4
  50. package/dist/utils/Requester/index.d.ts +5 -5
  51. package/dist/utils/Requester/types.d.ts +1 -1
  52. package/dist/utils/fetch.d.ts +2 -0
  53. package/package.json +2 -2
  54. package/dist/utils/Server/index.d.ts +0 -4
@@ -1,9 +1,6 @@
1
1
  import { Config } from '../utils/Config';
2
- import { NileRequest, NileResponse } from '../utils/Requester';
3
- export interface Tenant {
4
- id: string;
5
- name?: string;
6
- }
2
+ import { NileRequest } from '../utils/Requester';
3
+ import { Tenant } from './types';
7
4
  export default class Tenants extends Config {
8
5
  headers?: Headers;
9
6
  constructor(config: Config, headers?: Headers);
@@ -12,8 +9,14 @@ export default class Tenants extends Config {
12
9
  get tenantUrl(): string;
13
10
  createTenant: (req: NileRequest<{
14
11
  name: string;
15
- }>, init?: RequestInit) => NileResponse<Tenant>;
16
- getTenant: (req: NileRequest<void>, init?: RequestInit) => NileResponse<Tenant>;
12
+ }> | Headers | string, init?: RequestInit) => Promise<Tenant | Response>;
13
+ getTenant: (req: NileRequest<{
14
+ id: string;
15
+ }> | Headers | string | void, init?: RequestInit) => Promise<Tenant | Response>;
17
16
  get tenantListUrl(): string;
18
- listTenants: (req: NileRequest<void>, init?: RequestInit) => Promise<Response>;
17
+ listTenants: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<Tenant[] | Response>;
18
+ deleteTenant: (req: NileRequest<void> | Headers | string, init?: RequestInit) => Promise<Response>;
19
+ updateTenant: (req: NileRequest<void> | Headers | {
20
+ name: string;
21
+ }, init?: RequestInit) => Promise<Tenant | Response>;
19
22
  }
@@ -0,0 +1,4 @@
1
+ export interface Tenant {
2
+ id: string;
3
+ name?: string;
4
+ }
package/dist/types.d.ts CHANGED
@@ -6,6 +6,12 @@ export type Opts = {
6
6
  export type NilePoolConfig = PoolConfig & {
7
7
  afterCreate?: AfterCreate;
8
8
  };
9
+ export type LoggerType = {
10
+ info?: (args: unknown[]) => void;
11
+ warn?: (args: unknown[]) => void;
12
+ error?: (args: unknown[]) => void;
13
+ debug?: (args: unknown[]) => void;
14
+ };
9
15
  export type ServerConfig = {
10
16
  databaseId?: string;
11
17
  user?: string;
@@ -14,6 +20,8 @@ export type ServerConfig = {
14
20
  tenantId?: string | null | undefined;
15
21
  userId?: string | null | undefined;
16
22
  debug?: boolean;
23
+ configureUrl?: string;
24
+ secureCookies?: boolean;
17
25
  db?: NilePoolConfig;
18
26
  api?: {
19
27
  version?: number;
@@ -21,6 +29,7 @@ export type ServerConfig = {
21
29
  cookieKey?: string;
22
30
  token?: string;
23
31
  };
32
+ logger?: LoggerType;
24
33
  };
25
34
  export type NileDb = NilePoolConfig & {
26
35
  tenantId?: string;
@@ -1,52 +1,27 @@
1
1
  import { Config } from '../utils/Config';
2
- import { NileRequest, NileResponse } from '../utils/Requester';
3
- export interface CreateBasicUserRequest {
4
- email: string;
5
- password: string;
6
- preferredName?: string;
7
- newTenant?: string;
8
- }
9
- export declare const LoginUserResponseTokenTypeEnum: {
10
- readonly AccessToken: "ACCESS_TOKEN";
11
- readonly RefreshToken: "REFRESH_TOKEN";
12
- readonly IdToken: "ID_TOKEN";
13
- };
14
- export type LoginUserResponseTokenTypeEnum = (typeof LoginUserResponseTokenTypeEnum)[keyof typeof LoginUserResponseTokenTypeEnum];
15
- export interface LoginUserResponseToken {
16
- jwt: string;
17
- maxAge: number;
18
- type: LoginUserResponseTokenTypeEnum;
19
- }
20
- export interface LoginUserResponse {
21
- [key: string]: any;
22
- id: string;
23
- token: LoginUserResponseToken;
24
- }
25
- export interface User {
26
- id?: string;
27
- tenants?: Set<string>;
28
- email?: string;
29
- preferredName?: string;
30
- }
2
+ import { NileRequest } from '../utils/Requester';
3
+ import { CreateBasicUserRequest, User } from './types';
31
4
  export default class Users extends Config {
32
5
  headers?: Headers;
33
6
  constructor(config: Config, headers?: Headers);
34
7
  get usersUrl(): string;
35
8
  get tenantUsersUrl(): string;
9
+ get linkUsersUrl(): string;
10
+ get tenantUserUrl(): string;
36
11
  handleHeaders(init?: RequestInit): RequestInit | undefined;
37
- createUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => NileResponse<LoginUserResponse>;
38
- updateUser: (userId: string, req: NileRequest<User>, init?: RequestInit) => NileResponse<User>;
39
- listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => NileResponse<User[]>;
12
+ createUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
13
+ createTenantUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => Promise<User | Response>;
14
+ updateUser: (req: NileRequest<Partial<Omit<User, "email" | "tenants" | "created" | "updated">>>, init?: RequestInit) => Promise<User | Response>;
15
+ listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User[] | Response>;
40
16
  linkUser: (req: NileRequest<{
41
17
  id: string;
42
- }> | Headers, init?: RequestInit) => NileResponse<User[]>;
43
- tenantUsersDeleteUrl: (userId?: string) => string;
44
- getUserId: (req: Headers | NileRequest<{
45
- id: string;
46
- }>) => Promise<any>;
18
+ tenantId?: string;
19
+ }> | Headers | string, init?: RequestInit) => Promise<User | Response>;
47
20
  unlinkUser: (req: NileRequest<{
48
21
  id: string;
49
- }> | Headers, init?: RequestInit) => NileResponse<User[]>;
22
+ tenantId?: string;
23
+ }> | Headers | string, init?: RequestInit) => Promise<Response>;
50
24
  get meUrl(): string;
51
- me: (req: NileRequest<void>, init?: RequestInit) => NileResponse<User>;
25
+ me: (req: NileRequest<void> | Headers, init?: RequestInit) => Promise<User | Response>;
26
+ updateMe: (req: NileRequest<Partial<Omit<User, "email" | "id" | "tenants" | "created" | "updated">>> | Headers, init?: RequestInit) => Promise<User | Response>;
52
27
  }
@@ -0,0 +1,36 @@
1
+ export interface CreateBasicUserRequest {
2
+ email: string;
3
+ password: string;
4
+ preferredName?: string;
5
+ newTenant?: string;
6
+ }
7
+ export declare const LoginUserResponseTokenTypeEnum: {
8
+ readonly AccessToken: "ACCESS_TOKEN";
9
+ readonly RefreshToken: "REFRESH_TOKEN";
10
+ readonly IdToken: "ID_TOKEN";
11
+ };
12
+ export type LoginUserResponseTokenTypeEnum = (typeof LoginUserResponseTokenTypeEnum)[keyof typeof LoginUserResponseTokenTypeEnum];
13
+ export interface LoginUserResponseToken {
14
+ jwt: string;
15
+ maxAge: number;
16
+ type: LoginUserResponseTokenTypeEnum;
17
+ }
18
+ export interface LoginUserResponse {
19
+ [key: string]: any;
20
+ id: string;
21
+ token: LoginUserResponseToken;
22
+ }
23
+ export interface User {
24
+ id: string;
25
+ email: string;
26
+ name: string | null;
27
+ familyName: string | null;
28
+ givenName: string | null;
29
+ picture: string | null;
30
+ created: string;
31
+ updated: string;
32
+ emailVerified: boolean | null;
33
+ tenants: {
34
+ id: string;
35
+ }[];
36
+ }
@@ -4,19 +4,19 @@ export type EnvConfig = {
4
4
  logger?: string;
5
5
  config?: ServerConfig;
6
6
  };
7
+ export declare const getSecureCookies: (cfg: EnvConfig) => boolean | undefined;
7
8
  export declare const getDatabaseId: (cfg: EnvConfig) => string | undefined;
8
9
  export declare const getUsername: (cfg: EnvConfig) => string | undefined;
9
10
  export declare const getPassword: (cfg: EnvConfig) => string | undefined;
10
11
  export declare const getInfoBearer: (cfg: EnvConfig) => string;
11
12
  export declare const getToken: (cfg: EnvConfig) => string | undefined;
12
- export declare const getDatabaseName: (cfg: EnvConfig) => string | null;
13
+ export declare const getDatabaseName: (cfg: EnvConfig) => string | null | undefined;
13
14
  export declare const getTenantId: (cfg: EnvConfig) => string | null;
14
- export declare const getLocal: (cfg: EnvConfig) => string;
15
15
  /**
16
16
  * @param cfg various overrides
17
17
  * @returns the url for REST to use
18
18
  */
19
- export declare const getBasePath: (cfg: EnvConfig) => string;
20
- export declare const getControlPlane: (cfg: EnvConfig) => string;
21
- export declare function getDbHost(cfg: EnvConfig): string;
19
+ export declare const getBasePath: (cfg: EnvConfig) => undefined | string;
20
+ export declare const getControlPlane: (cfg: EnvConfig) => string | undefined;
21
+ export declare function getDbHost(cfg: EnvConfig): string | undefined;
22
22
  export declare function getDbPort(cfg: EnvConfig): number;
@@ -1,4 +1,4 @@
1
- import { NilePoolConfig, ServerConfig } from '../../types';
1
+ import { LoggerType, NilePoolConfig, ServerConfig } from '../../types';
2
2
  export type ConfigRoutes = {
3
3
  SIGNIN?: string;
4
4
  SESSION?: string;
@@ -8,19 +8,18 @@ export type ConfigRoutes = {
8
8
  SIGNOUT?: string;
9
9
  ME?: string;
10
10
  ERROR?: string;
11
+ TENANTS?: string;
12
+ TENANT_USERS?: string;
13
+ USERS?: string;
11
14
  };
12
15
  declare class ApiConfig {
13
16
  cookieKey?: string;
14
- basePath?: string;
15
- version?: number;
16
- localPath?: string;
17
+ basePath?: string | undefined;
17
18
  private _token?;
18
- constructor({ basePath, cookieKey, token, version, localPath, }: {
19
- basePath: string;
19
+ constructor({ basePath, cookieKey, token, }: {
20
+ basePath?: string | undefined;
20
21
  cookieKey: string;
21
22
  token: string | undefined;
22
- version: number;
23
- localPath: string;
24
23
  });
25
24
  get token(): string | undefined;
26
25
  set token(value: string | undefined);
@@ -32,6 +31,8 @@ export declare class Config {
32
31
  databaseName: string;
33
32
  routePrefix?: string;
34
33
  routes?: ConfigRoutes;
34
+ logger?: LoggerType;
35
+ secureCookies?: boolean | undefined;
35
36
  debug: boolean;
36
37
  db: NilePoolConfig;
37
38
  api: ApiConfig;
@@ -7,6 +7,5 @@ export declare const watchUserId: (cb: EventFn) => void;
7
7
  export declare const updateToken: (val: BusValues) => void;
8
8
  export declare const watchToken: (cb: EventFn) => void;
9
9
  export declare const watchEvictPool: (cb: EventFn) => void;
10
- export declare const closeEvictPool: (cb: EventFn) => void;
11
10
  export declare const evictPool: (val: BusValues) => void;
12
11
  export {};
@@ -1,7 +1,8 @@
1
1
  import { ServerConfig } from '../types';
2
2
  import { Config } from './Config';
3
- export default function Logger(config: void | Config | ServerConfig, ...params: unknown[]): {
4
- info(...args: unknown[]): void;
5
- warn(...args: unknown[]): void;
6
- error(...args: unknown[]): void;
3
+ export default function Logger(config?: Config | ServerConfig, ...params: unknown[]): {
4
+ info: (message: string | unknown, meta?: Record<string, unknown>) => void;
5
+ warn: (message: string | unknown, meta?: Record<string, unknown>) => void;
6
+ error: (message: string | unknown, meta?: Record<string, unknown>) => void;
7
+ debug: (message: string | unknown, meta?: Record<string, unknown>) => void;
7
8
  };
@@ -5,7 +5,7 @@ export default class Requester<T> extends Config {
5
5
  constructor(config: Config);
6
6
  rawRequest(method: Methods, url: string, init: RequestInit, body?: string): Promise<Response>;
7
7
  /**
8
- * three optios here
8
+ * three options here
9
9
  * 1) pass in headers for a server side request
10
10
  * 2) pass in the payload that matches the api
11
11
  * 3) pass in the request object sent by a browser
@@ -16,8 +16,8 @@ export default class Requester<T> extends Config {
16
16
  * @returns
17
17
  */
18
18
  protected request(method: Methods, url: string, req: T | Headers, init?: RequestInit): Promise<Response>;
19
- post: (req: T | Headers, url: string, init?: RequestInit) => Promise<Response>;
20
- get: (req: T | Headers, url: string, init?: RequestInit) => Promise<Response>;
21
- put: (req: T | Headers, url: string, init?: RequestInit) => Promise<Response>;
22
- delete: (req: T | Headers, url: string, init?: RequestInit) => Promise<Response>;
19
+ post<R = JSON>(req: T | Headers, url: string, init?: RequestInit): Promise<Response | R>;
20
+ get<R = JSON>(req: T | Headers, url: string, init?: RequestInit): Promise<Response | R>;
21
+ put<R = JSON>(req: T | Headers, url: string, init?: RequestInit): Promise<Response | R>;
22
+ delete(req: T | Headers, url: string, init?: RequestInit): Promise<Response>;
23
23
  }
@@ -84,5 +84,5 @@ export interface APIError {
84
84
  */
85
85
  statusCode: number;
86
86
  }
87
- export type NileResponse<T> = Promise<NResponse<T & APIError>>;
87
+ export type NileResponse<T> = Promise<T | NResponse<T & APIError>>;
88
88
  export {};
@@ -3,7 +3,9 @@ import { Config } from './Config';
3
3
  import { NileRequest } from './Requester';
4
4
  export declare const X_NILE_TENANT = "niledb-tenant-id";
5
5
  export declare const X_NILE_USER_ID = "niledb-user-id";
6
+ export declare const X_NILE_SECURECOOKIES = "niledb-useSecureCookies";
6
7
  export declare function handleTenantId(req: NileRequest<any>, config: Config): ResponseError | void;
7
8
  export declare function getTenantFromHttp(headers: Headers, config?: Config): string | null | undefined;
8
9
  export declare function getUserFromHttp(headers: Headers, config: Config): string | null | undefined;
10
+ export declare function makeBasicHeaders(config: Config, opts?: RequestInit): Headers;
9
11
  export declare function _fetch(config: Config, path: string, opts?: RequestInit): Promise<Response | ResponseError>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niledatabase/server",
3
- "version": "3.0.0-alpha.4",
3
+ "version": "3.0.0-alpha.40",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/server.esm.js",
@@ -74,5 +74,5 @@
74
74
  "jose": "^4.15.4",
75
75
  "pg": "^8.11.3"
76
76
  },
77
- "gitHead": "52ad5379abd61930e2d984495cba8b4b8b5803c4"
77
+ "gitHead": "bf5933e46ee24dde9d4135fbc2e993b9e804a6b6"
78
78
  }
@@ -1,4 +0,0 @@
1
- import { ServerConfig } from '../../types';
2
- import { Config } from '../Config';
3
- export declare const getServerId: (config: ServerConfig) => string;
4
- export declare const makeServerId: (config: Config) => string;