Skip to content

Commit

Permalink
fix(server): update types for getInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
jrea committed Apr 2, 2024
1 parent c1abdb0 commit dc0bbb9
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 22 deletions.
2 changes: 1 addition & 1 deletion packages/server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
dist
*.env*
.env*
3 changes: 2 additions & 1 deletion packages/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ await nile.api.createTenant({ name: 'name' });
await nile.db.query('select * from todo');
```

## Autoconfiguration
## Auto-configuration

In addition to `user` and `password`, a fully configured SDK must also have values for `db.host`, `databaseName`, and `databaseId`. If the values are not provided in either the `.env` file or the instance configuration, the SDK will automatically phone home to configure itself. For production, it is recommended to set those values.

Expand All @@ -53,6 +53,7 @@ Configuration passed to `Server` takes precedence over `.env` vars.
| tenantId | `string` | NILEDB_TENANT | ID of the tenant associated. |
| userId | `string` | | ID of the user associated. |
| db | `PoolConfig` | | Configuration object for [pg.Pool](https://node-postgres.com/apis/pool). |
| db.host | `string` | NILEDB_HOST | Base host for DB. Defaut is `db.thenile.dev` |
| api | `object` | | Configuration object for API settings. |
| api.basePath | `string` | NILEDB_API | Base host for API for a specific region. Default is `api.thenile.dev`. |
| api.cookieKey | `string` | | Key for API cookie. Default is `token`. |
Expand Down
18 changes: 18 additions & 0 deletions packages/server/example.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# env vars for running the integration test
# generated creds from dev/prod
NILEDB_USER=
NILEDB_PASSWORD=

# comment out for prod
NILEDB_API=api.dev.thenile.dev
NILEDB_HOST=db.dev.thenile.dev

# tenant where a user is
NILEDB_TENANT=

# user and password for login
EMAIL=
PASSWORD=

# test verification that the user above is this user
USER_ID=
2 changes: 1 addition & 1 deletion packages/server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ module.exports = {
testEnvironment: 'node',
};

process.env.NODE_ENV = 'TEST';
process.env.NODE_ENV = process.env.NODE_ENV ?? 'TEST';
1 change: 1 addition & 0 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build:spec": "yarn swagger-cli bundle openapi/index.json --outfile openapi/spec.json -r",
"build": "yarn build:spec && dts build --tsconfig ./tsconfig.build.json",
"test": "dts test",
"integration": "NODE_ENV=DEV dts test integration",
"lint": "eslint src",
"size": "size-limit",
"analyze": "size-limit --why"
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Pool } from 'pg';

import { InstanceConfig, ServerConfig } from './types';
import { ServerConfig } from './types';
import { Config } from './utils/Config';
import Auth from './auth';
import Users from './users';
Expand Down Expand Up @@ -123,7 +123,7 @@ class Server {
* or a new one if the config isn't in the cache
*/

getInstance(config: InstanceConfig): Server {
getInstance(config: ServerConfig): Server {
const _config = { ...this.config, ...config };
const serverId = getServerId(_config);
const currentServerId = makeServerId(this.config);
Expand Down
15 changes: 0 additions & 15 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ export type ServerConfig = {
};
};

export type InstanceConfig = {
databaseId: string;
user: string;
password: string;
tenantId?: string | null | undefined;
userId?: string | null | undefined;
debug?: boolean;
db?: NilePoolConfig;
api?: {
basePath?: string;
cookieKey?: string;
token?: string;
};
};

export type NileDb = NilePoolConfig & { tenantId?: string };

export type AfterCreate = (
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/utils/Config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ export class Config {
);
}
}

if (typeof database === 'object') {
const { apiHost, dbHost, name, id } = database;
this.databaseId = id;
Expand Down
2 changes: 1 addition & 1 deletion packages/server/test/integration/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ describe.skip('api integration', () => {

const tenants = await nile.api.tenants.getTenant();
body = await toJSON(tenants.body);
expect(body.id).toEqual(process.env.TENANT_ID);
expect(body.id).toEqual(process.env.NILEDB_TENANT);
});
});

Expand Down

0 comments on commit dc0bbb9

Please sign in to comment.