diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..108be71 --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +BASE_URL= +USER_NAME= +USER_PASSWORD= +DATABASE_NAME= \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4538ddb..921eba5 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ pnpm-workspace.yaml pnpmfile.js *.log *.log.* +.env \ No newline at end of file diff --git a/dist/index.cjs b/dist/index.cjs index 9319707..004a16d 100644 --- a/dist/index.cjs +++ b/dist/index.cjs @@ -1,5 +1,5 @@ /*! - * prest-client v0.0.2 + * prest-client v0.0.3 * (c) pgEdge * Released under the MIT License. */ diff --git a/dist/index.esm.js b/dist/index.esm.js index 5b3f08a..d2a57fa 100644 --- a/dist/index.esm.js +++ b/dist/index.esm.js @@ -1,5 +1,5 @@ /*! - * prest-client v0.0.2 + * prest-client v0.0.3 * (c) pgEdge * Released under the MIT License. */ diff --git a/dist/index.js b/dist/index.js index 554f02b..6dcb1ab 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,5 +1,5 @@ /*! - * prest-client v0.0.2 + * prest-client v0.0.3 * (c) pgEdge * Released under the MIT License. */ diff --git a/dist/index.mjs b/dist/index.mjs index bb59263..93b477c 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -1,5 +1,5 @@ /*! - * prest-client v0.0.2 + * prest-client v0.0.3 * (c) pgEdge * Released under the MIT License. */ diff --git a/dist/index.umd.js b/dist/index.umd.js index db133be..9a50e8c 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -1,5 +1,5 @@ /*! - * prest-client v0.0.2 + * prest-client v0.0.3 * (c) pgEdge * Released under the MIT License. */ diff --git a/dist/index.umd.min.js b/dist/index.umd.min.js index 365266e..bfe226b 100644 --- a/dist/index.umd.min.js +++ b/dist/index.umd.min.js @@ -1,5 +1,5 @@ /*! - * prest-client v0.0.2 + * prest-client v0.0.3 * (c) pgEdge * Released under the MIT License. */ diff --git a/docs/classes/PrestApiClient.md b/docs/classes/PrestApiClient.md index 18dc24e..c615ac0 100644 --- a/docs/classes/PrestApiClient.md +++ b/docs/classes/PrestApiClient.md @@ -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 @@ -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) ___ @@ -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 @@ -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 @@ -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) ___ @@ -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) diff --git a/docs/interfaces/PrestApiClientOptions.md b/docs/interfaces/PrestApiClientOptions.md index 363ad12..42a1051 100644 --- a/docs/interfaces/PrestApiClientOptions.md +++ b/docs/interfaces/PrestApiClientOptions.md @@ -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) ___ @@ -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) ___ @@ -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) ___ @@ -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) diff --git a/package.json b/package.json index 2f719ea..1130add 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" } } diff --git a/src/api/client.test.ts b/src/api/client.test.ts index a156f71..907e464 100644 --- a/src/api/client.test.ts +++ b/src/api/client.test.ts @@ -1,4 +1,5 @@ import { PrestApiClient, type PrestApiClientOptions } from './client'; +import envs from '../env.config'; jest.mock('node-fetch'); @@ -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); }); diff --git a/src/env.config.ts b/src/env.config.ts new file mode 100644 index 0000000..82b1745 --- /dev/null +++ b/src/env.config.ts @@ -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'] ?? '', +}; diff --git a/tsconfig.json b/tsconfig.json index bdcb3ce..7a4bc80 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] } diff --git a/types/env.config.d.ts b/types/env.config.d.ts new file mode 100644 index 0000000..a7ee67b --- /dev/null +++ b/types/env.config.d.ts @@ -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 \ No newline at end of file diff --git a/types/env.config.d.ts.map b/types/env.config.d.ts.map new file mode 100644 index 0000000..f4df1b0 --- /dev/null +++ b/types/env.config.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"env.config.d.ts","sourceRoot":"","sources":["../src/env.config.ts"],"names":[],"mappings":";;;;;;AAGA,wBAKE"} \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index e94fb0d..a698684 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"