@hyphen/sdk 1.5.0 → 1.6.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/README.md CHANGED
@@ -489,7 +489,14 @@ console.log('Boolean toggle value:', result); // true
489
489
  Hyphens secret management service known as [ENV](https://hyphen.ai/env) allows you to manage your environment variables in a secure way. The Hyphen Node.js SDK provides a simple way to access your environment variables.
490
490
 
491
491
  ## Loading Environment Variables
492
- To load your environment variables, you can use the `loadEnv` function from the SDK. This function will automatically load your environment variables from the `.env` file and then override them with the environment based environment file if it exists (ex: `.env.development`). This is useful for managing different environments such as development, staging, and production.
492
+ To load your environment variables, you can use the `loadEnv` function from the SDK. This function will automatically load your environment variables from the `.env` file and then override them with the environment based environment file if it exists (ex: `.env.development`). This is useful for managing different environments such as development, staging, and production.
493
+
494
+ The following override path is:
495
+ ```
496
+ .env -> .env.local -> .env.<environment> -> .env.<environment>.local
497
+ ```
498
+
499
+ Here is an example of how to use the `loadEnv` function:
493
500
 
494
501
  ```javascript
495
502
  import { loadEnv } from '@hyphen/sdk';
@@ -514,6 +521,14 @@ import { loadEnv } from '@hyphen/sdk';
514
521
  loadEnv({ environment: 'development' });
515
522
  ```
516
523
 
524
+ if you want to turn off the local environment variables you can do it like this:
525
+
526
+ ```javascript
527
+ import { loadEnv } from '@hyphen/sdk';
528
+ //load your default environment variables and envrionment variables
529
+ loadEnv({ local: false });
530
+ ```
531
+
517
532
  # Contributing
518
533
 
519
534
  We welcome contributions to the Hyphen Node.js SDK! If you have an idea for a new feature, bug fix, or improvement, please follow these steps:
package/dist/index.cjs CHANGED
@@ -404,6 +404,7 @@ var import_node_fs = __toESM(require("fs"), 1);
404
404
  var import_node_path = __toESM(require("path"), 1);
405
405
  var import_dotenv2 = require("dotenv");
406
406
  function loadEnv(options) {
407
+ const local = options?.local ?? true;
407
408
  const currentWorkingDirectory = options?.path ?? import_node_process2.default.cwd();
408
409
  const envPath = import_node_path.default.resolve(currentWorkingDirectory, ".env");
409
410
  if (import_node_fs.default.existsSync(envPath)) {
@@ -411,6 +412,15 @@ function loadEnv(options) {
411
412
  path: envPath
412
413
  });
413
414
  }
415
+ if (local) {
416
+ const localEnvPath = import_node_path.default.resolve(currentWorkingDirectory, ".env.local");
417
+ if (import_node_fs.default.existsSync(localEnvPath)) {
418
+ (0, import_dotenv2.config)({
419
+ path: localEnvPath,
420
+ override: true
421
+ });
422
+ }
423
+ }
414
424
  const environment = options?.environment ?? import_node_process2.default.env.NODE_ENV;
415
425
  if (environment) {
416
426
  const envSpecificPath = import_node_path.default.resolve(currentWorkingDirectory, `.env.${environment}`);
@@ -420,6 +430,15 @@ function loadEnv(options) {
420
430
  override: true
421
431
  });
422
432
  }
433
+ if (local) {
434
+ const envLocalPath = import_node_path.default.resolve(currentWorkingDirectory, `.env.${environment}.local`);
435
+ if (import_node_fs.default.existsSync(envLocalPath)) {
436
+ (0, import_dotenv2.config)({
437
+ path: envLocalPath,
438
+ override: true
439
+ });
440
+ }
441
+ }
423
442
  }
424
443
  }
425
444
  __name(loadEnv, "loadEnv");
package/dist/index.d.cts CHANGED
@@ -205,6 +205,7 @@ declare class Toggle extends Hookified {
205
205
  type LoadEnvOptions = {
206
206
  path?: string;
207
207
  environment?: string;
208
+ local?: boolean;
208
209
  };
209
210
  /**
210
211
  * @description Helper function to load your environment variables based on your default .env file
package/dist/index.d.ts CHANGED
@@ -205,6 +205,7 @@ declare class Toggle extends Hookified {
205
205
  type LoadEnvOptions = {
206
206
  path?: string;
207
207
  environment?: string;
208
+ local?: boolean;
208
209
  };
209
210
  /**
210
211
  * @description Helper function to load your environment variables based on your default .env file
package/dist/index.js CHANGED
@@ -368,6 +368,7 @@ import fs from "fs";
368
368
  import path from "path";
369
369
  import { config } from "dotenv";
370
370
  function loadEnv(options) {
371
+ const local = options?.local ?? true;
371
372
  const currentWorkingDirectory = options?.path ?? process2.cwd();
372
373
  const envPath = path.resolve(currentWorkingDirectory, ".env");
373
374
  if (fs.existsSync(envPath)) {
@@ -375,6 +376,15 @@ function loadEnv(options) {
375
376
  path: envPath
376
377
  });
377
378
  }
379
+ if (local) {
380
+ const localEnvPath = path.resolve(currentWorkingDirectory, ".env.local");
381
+ if (fs.existsSync(localEnvPath)) {
382
+ config({
383
+ path: localEnvPath,
384
+ override: true
385
+ });
386
+ }
387
+ }
378
388
  const environment = options?.environment ?? process2.env.NODE_ENV;
379
389
  if (environment) {
380
390
  const envSpecificPath = path.resolve(currentWorkingDirectory, `.env.${environment}`);
@@ -384,6 +394,15 @@ function loadEnv(options) {
384
394
  override: true
385
395
  });
386
396
  }
397
+ if (local) {
398
+ const envLocalPath = path.resolve(currentWorkingDirectory, `.env.${environment}.local`);
399
+ if (fs.existsSync(envLocalPath)) {
400
+ config({
401
+ path: envLocalPath,
402
+ override: true
403
+ });
404
+ }
405
+ }
387
406
  }
388
407
  }
389
408
  __name(loadEnv, "loadEnv");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyphen/sdk",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "Hyphen SDK for Node.js",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",