@hyphen/sdk 1.5.0 → 1.7.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
@@ -7,7 +7,7 @@
7
7
 
8
8
  # Hyphen Node.js SDK
9
9
 
10
- The Hyphen Node.js SDK is a JavaScript library that allows developers to easily integrate Hyphen's feature flag service [Toggle](https://hyphen.ai/toggle) into their Node.js applications. In addition to Toggle, the SDK also provides ENV management capabilities such as loading environment variables from `.env` files, managing environment variables.
10
+ The Hyphen Node.js SDK is a JavaScript library that allows developers to easily integrate Hyphen's feature flag service [Toggle](https://hyphen.ai/toggle), secret management service [ENV](https://hyphen.ai/env), and geo information service [Net Info](https://hyphen.ai/net-info) into their Node.js applications.
11
11
 
12
12
  # Table of Contents
13
13
  - [Installation](#installation)
@@ -20,6 +20,9 @@ The Hyphen Node.js SDK is a JavaScript library that allows developers to easily
20
20
  - [Toggle Caching](#toggle-caching)
21
21
  - [Toggle Environment Variables](#toggle-environment-variables)
22
22
  - [Toggle Self-Hosted](#toggle-self-hosted)
23
+ - [ENV](#env)
24
+ - [Loading Environment Variables](#loading-environment-variables)
25
+ - [Net Info](#net-info)
23
26
  - [Contributing](#contributing)
24
27
  - [Testing Your Changes](#testing-your-changes)
25
28
  - [License and Copyright](#license-and-copyright)
@@ -489,7 +492,14 @@ console.log('Boolean toggle value:', result); // true
489
492
  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
493
 
491
494
  ## 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.
495
+ 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.
496
+
497
+ The following override path is:
498
+ ```
499
+ .env -> .env.local -> .env.<environment> -> .env.<environment>.local
500
+ ```
501
+
502
+ Here is an example of how to use the `loadEnv` function:
493
503
 
494
504
  ```javascript
495
505
  import { loadEnv } from '@hyphen/sdk';
@@ -514,6 +524,35 @@ import { loadEnv } from '@hyphen/sdk';
514
524
  loadEnv({ environment: 'development' });
515
525
  ```
516
526
 
527
+ if you want to turn off the local environment variables you can do it like this:
528
+
529
+ ```javascript
530
+ import { loadEnv } from '@hyphen/sdk';
531
+ //load your default environment variables and envrionment variables
532
+ loadEnv({ local: false });
533
+ ```
534
+
535
+ # Net Info (https://net.info)
536
+
537
+ The Hyphen Node.js SDK also provides a `NetInfo` class that allows you to fetch geo information about an IP address. This can be useful for debugging or logging purposes. You can read more about it:
538
+
539
+ * [Website](https://hyphen.ai/net-info)
540
+ * [Quick Start Guide](https://docs.hyphen.ai/docs/netinfo-quickstart)
541
+
542
+ To use the `NetInfo` class, you can do the following:
543
+
544
+ ```javascript
545
+ import { NetInfo } from '@hyphen/sdk';
546
+ const netInfo = new NetInfo({
547
+ apiKey: 'your_api_key',
548
+ });
549
+
550
+ const ipInfo = await netInfo.getIpInfo('8.8.8.8');
551
+ console.log('IP Info:', ipInfo);
552
+ ```
553
+
554
+ You can also set the API key using the `HYPHEN_API_KEY` environment variable. This is useful for keeping your API key secure and not hardcoding it in your code.
555
+
517
556
  # Contributing
518
557
 
519
558
  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:
@@ -551,10 +590,13 @@ Once you have created the project, added the toggles, and created your applicati
551
590
 
552
591
 
553
592
  ```bash
554
- HYPHEN_PUBLIC_API_KEY=your_api_key
593
+ HYPHEN_PUBLIC_API_KEY=your_public_api_key
594
+ HYPHEN_API_KEY=your_api_key
555
595
  HYPHEN_APPLICATION_ID=your_project_id
556
596
  ```
557
597
 
598
+ The `HYPHEN_PUBLIC_API_KEY` is the public API key for your Hyphen project, `HYPHEN_API_KEY` is the API key used for things such as `NetInfo` and is located under settings in the dashboard, and `HYPHEN_APPLICATION_ID` is the application ID for your Hyphen project.
599
+
558
600
  Then run the tests with the following command:
559
601
 
560
602
  ```bash
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.7.0",
4
4
  "description": "Hyphen SDK for Node.js",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -46,7 +46,10 @@
46
46
  "dependencies": {
47
47
  "@hyphen/openfeature-server-provider": "^1.0.7",
48
48
  "@openfeature/server-sdk": "^1.18.0",
49
+ "axios": "^1.10.0",
50
+ "cacheable": "^1.10.0",
49
51
  "dotenv": "^16.5.0",
50
- "hookified": "^1.9.0"
52
+ "hookified": "^1.9.0",
53
+ "pino": "^9.7.0"
51
54
  }
52
55
  }