Skip to content

Commit

Permalink
added dotenv support
Browse files Browse the repository at this point in the history
  • Loading branch information
KnockOutEZ committed Mar 1, 2024
1 parent a0b8e64 commit 1014e98
Show file tree
Hide file tree
Showing 17 changed files with 60 additions and 22 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BASE_URL=
USER_NAME=
USER_PASSWORD=
DATABASE_NAME=
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pnpm-workspace.yaml
pnpmfile.js
*.log
*.log.*
.env
2 changes: 1 addition & 1 deletion dist/index.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* prest-client v0.0.2
* prest-client v0.0.3
* (c) pgEdge
* Released under the MIT License.
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/index.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* prest-client v0.0.2
* prest-client v0.0.3
* (c) pgEdge
* Released under the MIT License.
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/index.umd.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.umd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions docs/classes/PrestApiClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Creates a new Prest API client with the provided options.

#### Defined in

[api/client.ts:55](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L55)
[api/client.ts:55](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L55)

## Properties

Expand All @@ -60,7 +60,7 @@ The underlying HTTP client for making requests to the Prest API.

#### Defined in

[api/client.ts:39](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L39)
[api/client.ts:39](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L39)

___

Expand All @@ -72,7 +72,7 @@ The options used to configure the client.

#### Defined in

[api/client.ts:48](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L48)
[api/client.ts:48](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L48)

## Accessors

Expand All @@ -88,7 +88,7 @@ Gets the name of the database to which the client is connected.

#### Defined in

[api/client.ts:123](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L123)
[api/client.ts:123](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L123)

## Methods

Expand Down Expand Up @@ -117,7 +117,7 @@ An object with methods for interacting with the table.

#### Defined in

[api/client.ts:96](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L96)
[api/client.ts:96](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L96)

___

Expand All @@ -133,4 +133,4 @@ Creates the underlying HTTP client with the necessary authentication headers.

#### Defined in

[api/client.ts:63](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L63)
[api/client.ts:63](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L63)
8 changes: 4 additions & 4 deletions docs/interfaces/PrestApiClientOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ The base URL of the Prest API endpoint.

#### Defined in

[api/client.ts:11](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L11)
[api/client.ts:11](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L11)

___

Expand All @@ -39,7 +39,7 @@ The name of the database to connect to.

#### Defined in

[api/client.ts:26](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L26)
[api/client.ts:26](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L26)

___

Expand All @@ -51,7 +51,7 @@ The password for authentication with the Prest API.

#### Defined in

[api/client.ts:21](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L21)
[api/client.ts:21](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L21)

___

Expand All @@ -63,4 +63,4 @@ The username for authentication with the Prest API.

#### Defined in

[api/client.ts:16](https://github.com/pgEdge/prest-client/blob/e308d3f/src/api/client.ts#L16)
[api/client.ts:16](https://github.com/pgEdge/prest-client/blob/a0b8e64/src/api/client.ts#L16)
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@rollup/plugin-terser": "^0.4.3",
"@types/eslint": "^8.44.3",
"@types/jest": "^29.5.5",
"@types/node": "^20.11.24",
"@types/prettier": "^3.0.0",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
Expand Down Expand Up @@ -66,6 +67,7 @@
"homepage": "https://github.com/pgEdge/prest-client#readme",
"dependencies": {
"axios": "^1.6.7",
"dotenv": "^16.4.5",
"node-fetch": "^3.3.2"
}
}
9 changes: 5 additions & 4 deletions src/api/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PrestApiClient, type PrestApiClientOptions } from './client';
import envs from '../env.config';

jest.mock('node-fetch');

Expand All @@ -7,10 +8,10 @@ describe('PrestApiClient', () => {

beforeEach(() => {
const options: PrestApiClientOptions = {
base_url: '',
user_name: '',
password: '',
database: '',
base_url: envs.BASE_URL,
user_name: envs.USER_NAME,
password: envs.USER_PASSWORD,
database: envs.DATABASE_NAME,
};
client = new PrestApiClient(options);
});
Expand Down
9 changes: 9 additions & 0 deletions src/env.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as dotenv from 'dotenv';
dotenv.config();

export default {
BASE_URL: process.env['BASE_URL'] ?? '',
USER_NAME: process.env['USER_NAME'] ?? '',
USER_PASSWORD: process.env['USER_PASSWORD'] ?? '',
DATABASE_NAME: process.env['DATABASE_NAME'] ?? '',
};
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"lib": ["ES2020","esnext", "dom"],
"skipDefaultLibCheck": true,
"skipLibCheck": true,
"types": ["jest"]
"types": ["jest","node"]
},
"include": ["./src/**/*.ts", "./src/**/*.tsx"]
"include": ["./src/**/*.ts", "./src/**/*.tsx", "src/env.config.ts"]
}
8 changes: 8 additions & 0 deletions types/env.config.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
declare const _default: {
BASE_URL: string;
USER_NAME: string;
USER_PASSWORD: string;
DATABASE_NAME: string;
};
export default _default;
//# sourceMappingURL=env.config.d.ts.map
1 change: 1 addition & 0 deletions types/env.config.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,13 @@
dependencies:
undici-types "~5.26.4"

"@types/node@^20.11.24":
version "20.11.24"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.11.24.tgz#cc207511104694e84e9fb17f9a0c4c42d4517792"
integrity sha512-Kza43ewS3xoLgCEpQrsT+xRo/EJej1y0kVYGiLFE1NEODXGzTfwiC6tXTLMQskn1X4/Rjlh0MQUvx9W+L9long==
dependencies:
undici-types "~5.26.4"

"@types/prettier@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-3.0.0.tgz#e9bc8160230d3a461dab5c5b41cceef1ef723057"
Expand Down Expand Up @@ -1286,6 +1293,11 @@ doctrine@^3.0.0:
dependencies:
esutils "^2.0.2"

dotenv@^16.4.5:
version "16.4.5"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.4.5.tgz#cdd3b3b604cb327e286b4762e13502f717cb099f"
integrity sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==

electron-to-chromium@^1.4.668:
version "1.4.685"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.685.tgz#3ce988e4dfbb3aa984840394b1d7064c01ad74c1"
Expand Down

0 comments on commit 1014e98

Please sign in to comment.