@hyphen/sdk 1.11.0 → 1.12.1

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
@@ -1,6 +1,7 @@
1
1
  ![Hyphen AI](https://github.com/Hyphen/nodejs-sdk/raw/main/logo.png)
2
2
 
3
3
  [![tests](https://github.com/Hyphen/nodejs-sdk/actions/workflows/tests.yaml/badge.svg)](https://github.com/Hyphen/nodejs-sdk/actions/workflows/tests.yaml)
4
+ [![codecov](https://codecov.io/gh/Hyphen/nodejs-sdk/graph/badge.svg?token=7SZ2hbuPR3)](https://codecov.io/gh/Hyphen/nodejs-sdk)
4
5
  [![npm](https://img.shields.io/npm/v/@hyphen/sdk)](https://www.npmjs.com/package/@hyphen/sdk)
5
6
  [![npm](https://img.shields.io/npm/dm/@hyphen/sdk)](https://www.npmjs.com/package/@hyphen/sdk)
6
7
  [![license](https://img.shields.io/github/license/Hyphen/nodejs-sdk)](https://github.com/hyphen/nodejs-sdk/blob/main/LICENSE)
@@ -25,9 +26,15 @@ The Hyphen Node.js SDK is a JavaScript library that allows developers to easily
25
26
  - [Net Info - Geo Information Service](#net-info---geo-information-service)
26
27
  - [Link - Short Code Service](#link---short-code-service)
27
28
  - [Creating a Short Code](#creating-a-short-code)
29
+ - [Updating a Short Code](#updating-a-short-code)
28
30
  - [Getting a Short Code](#getting-a-short-code)
29
31
  - [Getting Short Codes](#getting-short-codes)
32
+ - [Getting all Organization Tags](#getting-all-organization-tags)
33
+ - [Getting Short Code Stats](#getting-short-code-stats)
30
34
  - [Deleting a Short Code](#deleting-a-short-code)
35
+ - [Creating a QR Code from a Short Code](#creating-a-qr-code-from-a-short-code)
36
+ - [Get QR Codes for a Short Code](#get-qr-codes-for-a-short-code)
37
+ - [Deleting a QR Code](#deleting-a-qr-code)
31
38
  - [Contributing](#contributing)
32
39
  - [Testing Your Changes](#testing-your-changes)
33
40
  - [License and Copyright](#license-and-copyright)
@@ -581,44 +588,44 @@ console.log('Boolean toggle value:', result); // true
581
588
  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.
582
589
 
583
590
  ## Loading Environment Variables
584
- 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.
591
+ To load your environment variables, you can use the `env()` 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.
585
592
 
586
593
  The following override path is:
587
594
  ```
588
595
  .env -> .env.local -> .env.<environment> -> .env.<environment>.local
589
596
  ```
590
597
 
591
- Here is an example of how to use the `loadEnv` function:
598
+ Here is an example of how to use the `env()` function:
592
599
 
593
600
  ```javascript
594
- import { loadEnv } from '@hyphen/sdk';
601
+ import { env } from '@hyphen/sdk';
595
602
 
596
603
  //load your default environment variables and envrionment variables
597
- loadEnv();
604
+ env();
598
605
  ```
599
606
 
600
607
  If your environment variables are not stored in the root of your project you can specify the path to your `.env` file:
601
608
 
602
609
  ```javascript
603
- import { loadEnv } from '@hyphen/sdk';
610
+ import { env } from '@hyphen/sdk';
604
611
  //load your default environment variables and envrionment variables
605
- loadEnv({ path: '/path/to/your/env/files/' });
612
+ env({ path: '/path/to/your/env/files/' });
606
613
  ```
607
614
 
608
615
  You can also specify the environment variables to load by passing an array of variable names:
609
616
 
610
617
  ```javascript
611
- import { loadEnv } from '@hyphen/sdk';
618
+ import { env } from '@hyphen/sdk';
612
619
  //load your default environment variables and envrionment variables
613
- loadEnv({ environment: 'development' });
620
+ env({ environment: 'development' });
614
621
  ```
615
622
 
616
623
  if you want to turn off the local environment variables you can do it like this:
617
624
 
618
625
  ```javascript
619
- import { loadEnv } from '@hyphen/sdk';
626
+ import { env } from '@hyphen/sdk';
620
627
  //load your default environment variables and envrionment variables
621
- loadEnv({ local: false });
628
+ env({ local: false });
622
629
  ```
623
630
 
624
631
  # Net Info - Geo Information Service
@@ -681,6 +688,27 @@ const response = await link.createShortCode(longUrl, domain, options);
681
688
  console.log('Short Code Response:', response);
682
689
  ```
683
690
 
691
+ ## Updating a Short Code
692
+ To update a short code, you can use the `updateShortCode` method:
693
+
694
+ ```javascript
695
+ import { Link } from '@hyphen/sdk';
696
+ const link = new Link({
697
+ organizationId: 'your_organization_id',
698
+ apiKey: 'your_api_key',
699
+ });
700
+ const code = 'code_1234567890'; // It is the code identifier for the short code you want to update
701
+ const longUrl = 'https://hyphen.ai/updated';
702
+ const options = {
703
+ title: 'Updated Short Code',
704
+ tags: ['sdk-test', 'unit-test'],
705
+ long_url: longUrl,
706
+ };
707
+
708
+ const updateResponse = await link.updateShortCode(code, options);
709
+ console.log('Update Short Code Response:', updateResponse);
710
+ ```
711
+
684
712
  ## Getting a Short Code
685
713
  To get a short code, you can use the `getShortCode` method:
686
714
 
@@ -710,6 +738,37 @@ const response = await link.getShortCodes(title, tags);
710
738
  console.log('Get Short Codes Response:', response);
711
739
  ```
712
740
 
741
+ ## Getting all Organization Tags
742
+
743
+ To get all tags for your organization, you can use the `getTags` method:
744
+
745
+ ```javascript
746
+ import { Link } from '@hyphen/sdk';
747
+ const link = new Link({
748
+ organizationId: 'your_organization_id',
749
+ apiKey: 'your_api_key',
750
+ });
751
+ const response = await link.getTags();
752
+ console.log('Get Tags Response:', response);
753
+ ```
754
+
755
+ ## Get Short Code Stats
756
+
757
+ To get the stats for a short code, you can use the `getShortCodeStats` method:
758
+
759
+ ```javascript
760
+ import { Link } from '@hyphen/sdk';
761
+ const link = new Link({
762
+ organizationId: 'your_organization_id',
763
+ apiKey: 'your_api_key',
764
+ });
765
+ const code = 'code_1234567890'; // It is the code identifier for the short code
766
+ const startDate = new Date('2023-01-01'); // Optional start date for the stats
767
+ const endDate = new Date('2023-12-31'); // Optional end date for the stats
768
+ const response = await link.getShortCodeStats(code, startDate, endDate);
769
+ console.log('Get Short Code Stats Response:', response);
770
+ ```
771
+
713
772
  ## Deleting a Short Code
714
773
  if you want to delete a short code you can do it like this:
715
774
 
@@ -724,6 +783,100 @@ const response = await link.deleteShortCode(code);
724
783
  console.log('Delete Short Code Response:', response);
725
784
  ```
726
785
 
786
+ ## Creating a QR Code from a Short Code
787
+
788
+ To create a QR code from a short code, you can use the `createQrCode` method:
789
+
790
+ ```javascript
791
+ import { Link } from '@hyphen/sdk';
792
+ const link = new Link({
793
+ organizationId: 'your_organization_id',
794
+ apiKey: 'your_api_key',
795
+ });
796
+ const code = 'code_1234567890'; // It is the code identifier for the short code you want to create a QR code for
797
+ const response = await link.createQrCode(code);
798
+ console.log('Create QR Code Response:', response);
799
+ ```
800
+
801
+ There are options that you can pass in to the `createQrCode` method to customize the QR code:
802
+
803
+ ```typescript
804
+ export type CreateQrCodeOptions = {
805
+ /**
806
+ * The title of the QR code. This is used for display purposes.
807
+ * @default undefined
808
+ */
809
+ title?: string;
810
+ /**
811
+ * The background color of the QR code. This is a hex color code.
812
+ * @default '#ffffff'
813
+ */
814
+ backgroundColor?: string;
815
+ /**
816
+ * The color of the QR code. This is a hex color code.
817
+ * @default '#000000'
818
+ */
819
+ color?: string;
820
+ /**
821
+ * The size of the QR code. This can be 'small', 'medium', or 'large'.
822
+ * @default QrSize.MEDIUM
823
+ */
824
+ size?: QrSize;
825
+ /**
826
+ * The logo to include in the QR code. This should be a base64 encoded string.
827
+ * @default undefined
828
+ */
829
+ logo?: string;
830
+ };
831
+ ```
832
+
833
+ ## Get a QR Code By Id
834
+
835
+ To get a specific QR code by its ID, you can use the `getQrCode` method:
836
+
837
+ ```javascript
838
+ import { Link } from '@hyphen/sdk';
839
+ const link = new Link({
840
+ organizationId: 'your_organization_id',
841
+ apiKey: 'your_api_key',
842
+ });
843
+ const code = 'code_1234567890'; // It is the code identifier for the short code
844
+ const qr = 'qr_1234567890'; // It is the ID of the QR code you want to retrieve
845
+ const response = await link.getQrCode(code, qr);
846
+ console.log('Get QR Code Response:', response);
847
+ ```
848
+
849
+ ## Get QR Codes for a Short Code
850
+
851
+ To get all QR codes for a short code, you can use the `getQrCodes` method:
852
+
853
+ ```javascript
854
+ import { Link } from '@hyphen/sdk';
855
+ const link = new Link({
856
+ organizationId: 'your_organization_id',
857
+ apiKey: 'your_api_key',
858
+ });
859
+ const code = 'code_1234567890'; // It is the code identifier for the short code
860
+ const response = await link.getQrCodes(code);
861
+ console.log('Get QR Codes Response:', response);
862
+ ```
863
+
864
+ ## Deleting a QR Code
865
+
866
+ To delete a QR code, you can use the `deleteQrCode` method:
867
+
868
+ ```javascript
869
+ import { Link } from '@hyphen/sdk';
870
+ const link = new Link({
871
+ organizationId: 'your_organization_id',
872
+ apiKey: 'your_api_key',
873
+ });
874
+ const code = 'code_1234567890'; // It is the code identifier for the short code
875
+ const qr = 'qr_1234567890'; // It is the ID of the QR code you want to delete
876
+ const response = await link.deleteQrCode(code, qr);
877
+ console.log('Delete QR Code Response:', response);
878
+ ```
879
+
727
880
  # Contributing
728
881
 
729
882
  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: