@niledatabase/server 1.0.0 → 2.1.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/types.d.ts CHANGED
@@ -1,19 +1,20 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import 'knex';
4
- import { ConnectionOptions } from 'tls';
5
- import stream from 'node:stream';
6
- import { Knex } from 'knex';
1
+ import { PoolClient, PoolConfig } from 'pg';
7
2
  export type Opts = {
8
3
  basePath?: string;
9
4
  fetch?: typeof fetch;
10
5
  };
6
+ export type NilePoolConfig = PoolConfig & {
7
+ afterCreate?: AfterCreate;
8
+ };
11
9
  export type ServerConfig = {
12
- database: string;
10
+ databaseId?: string;
11
+ user?: string;
12
+ password?: string;
13
+ databaseName?: string;
13
14
  tenantId?: string | null | undefined;
14
15
  userId?: string | null | undefined;
15
- workspace: string;
16
- db?: Knex.Config;
16
+ debug?: boolean;
17
+ db?: NilePoolConfig;
17
18
  api?: {
18
19
  basePath?: string;
19
20
  cookieKey?: string;
@@ -21,58 +22,20 @@ export type ServerConfig = {
21
22
  };
22
23
  };
23
24
  export type InstanceConfig = {
24
- database?: string;
25
+ databaseId: string;
26
+ user: string;
27
+ password: string;
25
28
  tenantId?: string | null | undefined;
26
29
  userId?: string | null | undefined;
27
- workspace?: string;
28
- db?: Knex.Config;
30
+ debug?: boolean;
31
+ db?: NilePoolConfig;
29
32
  api?: {
30
33
  basePath?: string;
31
34
  cookieKey?: string;
32
35
  token?: string;
33
36
  };
34
37
  };
35
- export type NileDb = Knex & {
38
+ export type NileDb = NilePoolConfig & {
36
39
  tenantId?: string;
37
40
  };
38
- export type PgConnectionConfig = {
39
- user?: string;
40
- database?: string;
41
- password?: string | (() => string | Promise<string>);
42
- port?: number;
43
- host?: string;
44
- connectionString?: string;
45
- keepAlive?: boolean;
46
- stream?: stream.Duplex;
47
- statement_timeout?: false | number;
48
- parseInputDatesAsUTC?: boolean;
49
- ssl?: boolean | ConnectionOptions;
50
- query_timeout?: number;
51
- keepAliveInitialDelayMillis?: number;
52
- idle_in_transaction_session_timeout?: number;
53
- application_name?: string;
54
- connectionTimeoutMillis?: number;
55
- options?: string;
56
- expirationChecker?(): boolean;
57
- };
58
- export type AfterCreate = (conn: {
59
- on: any;
60
- query: (query: string, cb: (err: unknown) => void) => void;
61
- }, done: (err: unknown, conn: unknown) => void) => void;
62
- export type PoolConfig = {
63
- name?: string;
64
- afterCreate?: Function;
65
- min?: number;
66
- max?: number;
67
- refreshIdle?: boolean;
68
- idleTimeoutMillis?: number;
69
- reapIntervalMillis?: number;
70
- returnToHead?: boolean;
71
- priorityRange?: number;
72
- log?: (message: string, logLevel: string) => void;
73
- propagateCreateError?: boolean;
74
- createRetryIntervalMillis?: number;
75
- createTimeoutMillis?: number;
76
- destroyTimeoutMillis?: number;
77
- acquireTimeoutMillis?: number;
78
- };
41
+ export type AfterCreate = (conn: PoolClient, done: (err: null | Error, conn: PoolClient) => void) => void;
@@ -1,15 +1,42 @@
1
- import { RestModels } from '@niledatabase/js';
2
1
  import { Config } from '../utils/Config';
3
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
+ }
4
31
  export default class Users extends Config {
5
32
  constructor(config: Config);
6
33
  get baseUrl(): string;
7
34
  get usersUrl(): string;
8
35
  get tenantUsersUrl(): string;
9
- createTenantUser: (req: NileRequest<RestModels.CreateBasicUserRequest>, init?: RequestInit) => NileResponse<RestModels.LoginUserResponse>;
10
- listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => NileResponse<RestModels.User[]>;
11
- updateUser: (userId: string, req: NileRequest<RestModels.UpdateUserRequest>, init?: RequestInit) => NileResponse<RestModels.User>;
12
- listTenantUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => NileResponse<RestModels.User[]>;
36
+ createTenantUser: (req: NileRequest<CreateBasicUserRequest>, init?: RequestInit) => NileResponse<LoginUserResponse>;
37
+ listUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => NileResponse<User[]>;
38
+ updateUser: (userId: string, req: NileRequest<User>, init?: RequestInit) => NileResponse<User>;
39
+ listTenantUsers: (req: NileRequest<void> | Headers, init?: RequestInit) => NileResponse<User[]>;
13
40
  get meUrl(): string;
14
- me: (req: NileRequest<void>, init?: RequestInit) => NileResponse<RestModels.User>;
41
+ me: (req: NileRequest<void>, init?: RequestInit) => NileResponse<User>;
15
42
  }
@@ -0,0 +1,16 @@
1
+ import 'dotenv/config';
2
+ import { ServerConfig } from '../../types';
3
+ export type EnvConfig = {
4
+ logger?: string;
5
+ config?: ServerConfig;
6
+ };
7
+ export declare const getDatbaseId: (cfg: EnvConfig) => string | undefined;
8
+ export declare const getUsername: (cfg: EnvConfig) => string | undefined;
9
+ export declare const getPassword: (cfg: EnvConfig) => string | undefined;
10
+ export declare const getInfoBearer: (cfg: EnvConfig) => string;
11
+ export declare const getToken: (cfg: EnvConfig) => string | undefined;
12
+ export declare const getDatabaseName: (cfg: EnvConfig) => string | null;
13
+ export declare const getTenantId: (cfg: EnvConfig) => string | null;
14
+ export declare const getBasePath: (cfg: EnvConfig) => string;
15
+ export declare function getDbHost(cfg: EnvConfig): string;
16
+ export declare function getDbPort(cfg: EnvConfig): number;
@@ -1,4 +1,4 @@
1
- import { PgConnectionConfig, PoolConfig, ServerConfig } from '../types';
1
+ import { NilePoolConfig, ServerConfig } from '../../types';
2
2
  declare class ApiConfig {
3
3
  cookieKey?: string;
4
4
  basePath?: string;
@@ -11,14 +11,13 @@ declare class ApiConfig {
11
11
  get token(): string | undefined;
12
12
  set token(value: string | undefined);
13
13
  }
14
- type DBConfig = {
15
- connection: PgConnectionConfig;
16
- pool?: PoolConfig;
17
- };
18
14
  export declare class Config {
19
- database: string;
20
- workspace: string;
21
- db: DBConfig;
15
+ user: string;
16
+ password: string;
17
+ databaseId: string;
18
+ databaseName: string;
19
+ debug: boolean;
20
+ db: NilePoolConfig;
22
21
  api: ApiConfig;
23
22
  private _tenantId?;
24
23
  private _userId?;
@@ -26,6 +25,6 @@ export declare class Config {
26
25
  set tenantId(value: string | undefined | null);
27
26
  get userId(): string | undefined | null;
28
27
  set userId(value: string | undefined | null);
29
- constructor(_config?: ServerConfig);
28
+ constructor(config: ServerConfig, allowPhoneHome?: boolean);
30
29
  }
31
30
  export {};
@@ -0,0 +1,7 @@
1
+ import { ServerConfig } from '../types';
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;
7
+ };
@@ -1,4 +1,3 @@
1
- import { RestModels } from '@niledatabase/js';
2
1
  interface NileBody<R, B> {
3
2
  readonly body: ReadableStream<Uint8Array> | null | B;
4
3
  readonly bodyUsed: boolean;
@@ -48,5 +47,42 @@ interface NRequest<T> extends NileBody<any, T> {
48
47
  clone(): Request;
49
48
  }
50
49
  export type NileRequest<T> = NRequest<T> | T;
51
- export type NileResponse<T> = Promise<NResponse<T & RestModels.APIError>>;
50
+ export declare const APIErrorErrorCodeEnum: {
51
+ readonly InternalError: "internal_error";
52
+ readonly BadRequest: "bad_request";
53
+ readonly EntityNotFound: "entity_not_found";
54
+ readonly DuplicateEntity: "duplicate_entity";
55
+ readonly InvalidCredentials: "invalid_credentials";
56
+ readonly UnknownOidcProvider: "unknown_oidc_provider";
57
+ readonly ProviderAlreadyExists: "provider_already_exists";
58
+ readonly ProviderConfigError: "provider_config_error";
59
+ readonly ProviderMismatch: "provider_mismatch";
60
+ readonly ProviderUpdateError: "provider_update_error";
61
+ readonly SessionStateMissing: "session_state_missing";
62
+ readonly SessionStateMismatch: "session_state_mismatch";
63
+ readonly OidcCodeMissing: "oidc_code_missing";
64
+ };
65
+ export type APIErrorErrorCodeEnum = (typeof APIErrorErrorCodeEnum)[keyof typeof APIErrorErrorCodeEnum];
66
+ export interface APIError {
67
+ [key: string]: any | any;
68
+ /**
69
+ *
70
+ * @type {string}
71
+ * @memberof APIError
72
+ */
73
+ errorCode: APIErrorErrorCodeEnum;
74
+ /**
75
+ *
76
+ * @type {string}
77
+ * @memberof APIError
78
+ */
79
+ message: string;
80
+ /**
81
+ *
82
+ * @type {number}
83
+ * @memberof APIError
84
+ */
85
+ statusCode: number;
86
+ }
87
+ export type NileResponse<T> = Promise<NResponse<T & APIError>>;
52
88
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@niledatabase/server",
3
- "version": "1.0.0",
3
+ "version": "2.1.0",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -47,6 +47,9 @@
47
47
  "@apidevtools/swagger-cli": "^4.0.4",
48
48
  "@babel/core": "^7.23.3",
49
49
  "@types/jest": "^29.5.9",
50
+ "@types/mime": "^4.0.0",
51
+ "@types/pg": "^8.11.4",
52
+ "@types/sync-fetch": "^0",
50
53
  "@typescript-eslint/parser": "^5.62.0",
51
54
  "babel-loader": "^9.1.3",
52
55
  "dts-cli": "^2.0.3",
@@ -62,10 +65,11 @@
62
65
  "typescript": "^5.3.2"
63
66
  },
64
67
  "dependencies": {
65
- "@niledatabase/js": "^1.0.0",
68
+ "dotenv": "^16.4.5",
69
+ "install": "^0.13.0",
66
70
  "jose": "^4.15.4",
67
- "knex": "^2.5.1",
68
- "pg": "^8.11.3"
71
+ "pg": "^8.11.3",
72
+ "sync-fetch": "^0.5.2"
69
73
  },
70
- "gitHead": "c3be0e6a94604cf7576629c5ac9318a2cc5eb68e"
74
+ "gitHead": "a0ba85caf9f5a842cf3b2bcd5605e5ac0ea60999"
71
75
  }