@hyphen/sdk 1.10.0 → 1.12.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 +204 -11
- package/dist/index.cjs +264 -8
- package/dist/index.d.cts +182 -6
- package/dist/index.d.ts +182 -6
- package/dist/index.js +263 -8
- package/package.json +8 -7
package/dist/index.js
CHANGED
|
@@ -367,7 +367,7 @@ import process2 from "process";
|
|
|
367
367
|
import fs from "fs";
|
|
368
368
|
import path from "path";
|
|
369
369
|
import { config } from "dotenv";
|
|
370
|
-
function
|
|
370
|
+
function env(options) {
|
|
371
371
|
const local = options?.local ?? true;
|
|
372
372
|
const currentWorkingDirectory = options?.path ?? process2.cwd();
|
|
373
373
|
const envPath = path.resolve(currentWorkingDirectory, ".env");
|
|
@@ -405,7 +405,8 @@ function loadEnv(options) {
|
|
|
405
405
|
}
|
|
406
406
|
}
|
|
407
407
|
}
|
|
408
|
-
__name(
|
|
408
|
+
__name(env, "env");
|
|
409
|
+
var loadEnv = env;
|
|
409
410
|
|
|
410
411
|
// src/hyphen.ts
|
|
411
412
|
import { Hookified as Hookified3 } from "hookified";
|
|
@@ -479,6 +480,9 @@ var BaseService = class extends Hookified2 {
|
|
|
479
480
|
return axios.put(url, data, config2);
|
|
480
481
|
}
|
|
481
482
|
async delete(url, config2) {
|
|
483
|
+
if (config2 && config2.headers) {
|
|
484
|
+
delete config2.headers["content-type"];
|
|
485
|
+
}
|
|
482
486
|
return axios.delete(url, config2);
|
|
483
487
|
}
|
|
484
488
|
async patch(url, data, config2) {
|
|
@@ -497,7 +501,7 @@ var BaseService = class extends Hookified2 {
|
|
|
497
501
|
};
|
|
498
502
|
|
|
499
503
|
// src/net-info.ts
|
|
500
|
-
|
|
504
|
+
env();
|
|
501
505
|
var NetInfo = class extends BaseService {
|
|
502
506
|
static {
|
|
503
507
|
__name(this, "NetInfo");
|
|
@@ -626,7 +630,8 @@ var NetInfo = class extends BaseService {
|
|
|
626
630
|
|
|
627
631
|
// src/link.ts
|
|
628
632
|
import process4 from "process";
|
|
629
|
-
|
|
633
|
+
import { Buffer as Buffer2 } from "buffer";
|
|
634
|
+
env();
|
|
630
635
|
var defaultLinkUris = [
|
|
631
636
|
"https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"
|
|
632
637
|
];
|
|
@@ -706,11 +711,43 @@ var Link = class extends BaseService {
|
|
|
706
711
|
this._apiKey = apiKey;
|
|
707
712
|
}
|
|
708
713
|
}
|
|
714
|
+
/**
|
|
715
|
+
* Get the URI for a specific organization and code. This is used internally to construct the URI for the link service.
|
|
716
|
+
* @param {string} organizationId The ID of the organization.
|
|
717
|
+
* @param {string} code The code to include in the URI.
|
|
718
|
+
* @returns {string} The constructed URI.
|
|
719
|
+
*/
|
|
720
|
+
getUri(organizationId, prefix1, prefix2, prefix3) {
|
|
721
|
+
if (!organizationId) {
|
|
722
|
+
throw new Error("Organization ID is required to get the URI.");
|
|
723
|
+
}
|
|
724
|
+
let url = this._uris[0].replace("{organizationId}", organizationId);
|
|
725
|
+
if (prefix1) {
|
|
726
|
+
url = url.endsWith("/") ? `${url}${prefix1}/` : `${url}/${prefix1}`;
|
|
727
|
+
}
|
|
728
|
+
if (prefix2) {
|
|
729
|
+
url = url.endsWith("/") ? `${url}${prefix2}/` : `${url}/${prefix2}`;
|
|
730
|
+
}
|
|
731
|
+
if (prefix3) {
|
|
732
|
+
url = url.endsWith("/") ? `${url}${prefix3}/` : `${url}/${prefix3}`;
|
|
733
|
+
}
|
|
734
|
+
if (url.endsWith("/")) {
|
|
735
|
+
url = url.slice(0, -1);
|
|
736
|
+
}
|
|
737
|
+
return url;
|
|
738
|
+
}
|
|
739
|
+
/**
|
|
740
|
+
* Create a short code for a long URL.
|
|
741
|
+
* @param {string} longUrl The long URL to shorten.
|
|
742
|
+
* @param {string} domain The domain to use for the short code.
|
|
743
|
+
* @param {CreateShortCodeOptions} options Optional parameters for creating the short code.
|
|
744
|
+
* @returns {Promise<CreateShortCodeResponse>} A promise that resolves to the created short code details.
|
|
745
|
+
*/
|
|
709
746
|
async createShortCode(longUrl, domain, options) {
|
|
710
747
|
if (!this._organizationId) {
|
|
711
748
|
throw new Error("Organization ID is required to create a short code.");
|
|
712
749
|
}
|
|
713
|
-
const url = this.
|
|
750
|
+
const url = this.getUri(this._organizationId);
|
|
714
751
|
const body = {
|
|
715
752
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
716
753
|
long_url: longUrl,
|
|
@@ -729,6 +766,119 @@ var Link = class extends BaseService {
|
|
|
729
766
|
throw new Error(`Failed to create short code: ${response.statusText}`);
|
|
730
767
|
}
|
|
731
768
|
/**
|
|
769
|
+
* Get a short code by its code.
|
|
770
|
+
* @param {string} code The short code to retrieve. Example: 'code_686bed403c3991bd676bba4d'
|
|
771
|
+
* @returns {Promise<GetShortCodeResponse>} A promise that resolves to the short code details.
|
|
772
|
+
*/
|
|
773
|
+
async getShortCode(code) {
|
|
774
|
+
if (!this._organizationId) {
|
|
775
|
+
throw new Error("Organization ID is required to get a short code.");
|
|
776
|
+
}
|
|
777
|
+
const url = this.getUri(this._organizationId, code);
|
|
778
|
+
const headers = this.createHeaders(this._apiKey);
|
|
779
|
+
const response = await this.get(url, {
|
|
780
|
+
headers
|
|
781
|
+
});
|
|
782
|
+
if (response.status === 200) {
|
|
783
|
+
return response.data;
|
|
784
|
+
}
|
|
785
|
+
throw new Error(`Failed to get short code: ${response.statusText}`);
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Get all short codes for the organization.
|
|
789
|
+
* @param {string} titleSearch Optional search term to filter short codes by title.
|
|
790
|
+
* @param {string[]} tags Optional tags to filter short codes.
|
|
791
|
+
* @param {number} pageNumber The page number to retrieve. Default is 1.
|
|
792
|
+
* @param {number} pageSize The number of short codes per page. Default is 100.
|
|
793
|
+
* @returns {Promise<GetShortCodesResponse>} A promise that resolves to the list of short codes.
|
|
794
|
+
*/
|
|
795
|
+
async getShortCodes(titleSearch, tags, pageNumber = 1, pageSize = 100) {
|
|
796
|
+
if (!this._organizationId) {
|
|
797
|
+
throw new Error("Organization ID is required to get short codes.");
|
|
798
|
+
}
|
|
799
|
+
const url = this.getUri(this._organizationId);
|
|
800
|
+
const headers = this.createHeaders(this._apiKey);
|
|
801
|
+
const parameters = {};
|
|
802
|
+
if (titleSearch) {
|
|
803
|
+
parameters.title = titleSearch;
|
|
804
|
+
}
|
|
805
|
+
if (tags && tags.length > 0) {
|
|
806
|
+
parameters.tags = tags.join(",");
|
|
807
|
+
}
|
|
808
|
+
parameters.pageNum = pageNumber.toString();
|
|
809
|
+
parameters.pageSize = pageSize.toString();
|
|
810
|
+
const response = await this.get(url, {
|
|
811
|
+
headers,
|
|
812
|
+
params: parameters
|
|
813
|
+
});
|
|
814
|
+
if (response.status === 200) {
|
|
815
|
+
return response.data;
|
|
816
|
+
}
|
|
817
|
+
throw new Error(`Failed to get short codes: ${response.statusText}`);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Get all tags associated with the organization's short codes.
|
|
821
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of tags.
|
|
822
|
+
*/
|
|
823
|
+
async getTags() {
|
|
824
|
+
if (!this._organizationId) {
|
|
825
|
+
throw new Error("Organization ID is required to get tags.");
|
|
826
|
+
}
|
|
827
|
+
const url = this.getUri(this._organizationId, "tags");
|
|
828
|
+
const headers = this.createHeaders(this._apiKey);
|
|
829
|
+
const response = await this.get(url, {
|
|
830
|
+
headers
|
|
831
|
+
});
|
|
832
|
+
if (response.status === 200) {
|
|
833
|
+
return response.data;
|
|
834
|
+
}
|
|
835
|
+
throw new Error(`Failed to get tags: ${response.statusText}`);
|
|
836
|
+
}
|
|
837
|
+
/**
|
|
838
|
+
* Get statistics for a specific short code.
|
|
839
|
+
* @param code The short code to retrieve statistics for.
|
|
840
|
+
* @returns {Promise<GetCodeStatsResponse>} A promise that resolves to the code statistics.
|
|
841
|
+
*/
|
|
842
|
+
async getCodeStats(code, startDate, endDate) {
|
|
843
|
+
if (!this._organizationId) {
|
|
844
|
+
throw new Error("Organization ID is required to get code stats.");
|
|
845
|
+
}
|
|
846
|
+
const url = this.getUri(this._organizationId, code, "stats");
|
|
847
|
+
const headers = this.createHeaders(this._apiKey);
|
|
848
|
+
const parameters = {
|
|
849
|
+
startDate: startDate.toISOString(),
|
|
850
|
+
endDate: endDate.toISOString()
|
|
851
|
+
};
|
|
852
|
+
const response = await this.get(url, {
|
|
853
|
+
headers,
|
|
854
|
+
params: parameters
|
|
855
|
+
});
|
|
856
|
+
if (response.status === 200) {
|
|
857
|
+
return response.data;
|
|
858
|
+
}
|
|
859
|
+
throw new Error(`Failed to get code stats: ${response.statusText}`);
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Update a short code.
|
|
863
|
+
* @param {string} code The short code to update. Example: 'code_686bed403c3991bd676bba4d'
|
|
864
|
+
* @param {UpdateShortCodeOptions} options The options to update the short code with.
|
|
865
|
+
* @returns {Promise<UpdateShortCodeResponse>} A promise that resolves to the updated short code details.
|
|
866
|
+
*/
|
|
867
|
+
async updateShortCode(code, options) {
|
|
868
|
+
if (!this._organizationId) {
|
|
869
|
+
throw new Error("Organization ID is required to update a short code.");
|
|
870
|
+
}
|
|
871
|
+
const url = this.getUri(this._organizationId, code);
|
|
872
|
+
const headers = this.createHeaders(this._apiKey);
|
|
873
|
+
const response = await this.patch(url, options, {
|
|
874
|
+
headers
|
|
875
|
+
});
|
|
876
|
+
if (response.status === 200) {
|
|
877
|
+
return response.data;
|
|
878
|
+
}
|
|
879
|
+
throw new Error(`Failed to update short code: ${response.statusText}`);
|
|
880
|
+
}
|
|
881
|
+
/**
|
|
732
882
|
* Delete a short code.
|
|
733
883
|
* @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
|
|
734
884
|
* @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
|
|
@@ -737,10 +887,8 @@ var Link = class extends BaseService {
|
|
|
737
887
|
if (!this._organizationId) {
|
|
738
888
|
throw new Error("Organization ID is required to delete a short code.");
|
|
739
889
|
}
|
|
740
|
-
|
|
741
|
-
url = url.endsWith("/") ? `${url}${code}/` : `${url}/${code}/`;
|
|
890
|
+
const url = this.getUri(this._organizationId, code);
|
|
742
891
|
const headers = this.createHeaders(this._apiKey);
|
|
743
|
-
delete headers["content-type"];
|
|
744
892
|
const response = await this.delete(url, {
|
|
745
893
|
headers
|
|
746
894
|
});
|
|
@@ -749,6 +897,112 @@ var Link = class extends BaseService {
|
|
|
749
897
|
}
|
|
750
898
|
throw new Error(`Failed to delete short code: ${response.statusText}`);
|
|
751
899
|
}
|
|
900
|
+
/**
|
|
901
|
+
* Create a QR code for a specific short code.
|
|
902
|
+
* @param {string} code The short code to create a QR code for.
|
|
903
|
+
* @param {CreateQrCodeOptions} options The options for creating the QR code.
|
|
904
|
+
* @returns {Promise<CreateQrCodeResponse>} A promise that resolves to the created QR code details.
|
|
905
|
+
*/
|
|
906
|
+
async createQrCode(code, options) {
|
|
907
|
+
if (!this._organizationId) {
|
|
908
|
+
throw new Error("Organization ID is required to create a QR code.");
|
|
909
|
+
}
|
|
910
|
+
const url = this.getUri(this._organizationId, code, "qrs");
|
|
911
|
+
const headers = this.createHeaders(this._apiKey);
|
|
912
|
+
const body = {
|
|
913
|
+
title: options?.title,
|
|
914
|
+
backgroundColor: options?.backgroundColor,
|
|
915
|
+
color: options?.color,
|
|
916
|
+
size: options?.size,
|
|
917
|
+
logo: options?.logo
|
|
918
|
+
};
|
|
919
|
+
const response = await this.post(url, body, {
|
|
920
|
+
headers
|
|
921
|
+
});
|
|
922
|
+
if (response.status === 201) {
|
|
923
|
+
const result = response.data;
|
|
924
|
+
if (result.qrCode) {
|
|
925
|
+
const buffer = Buffer2.from(result.qrCode, "base64");
|
|
926
|
+
result.qrCodeBytes = new Uint16Array(buffer);
|
|
927
|
+
}
|
|
928
|
+
return result;
|
|
929
|
+
}
|
|
930
|
+
throw new Error(`Failed to create QR code: ${response.statusText}`);
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* Get a QR code by its ID.
|
|
934
|
+
* @param code The short code associated with the QR code.
|
|
935
|
+
* @param qr The ID of the QR code to retrieve.
|
|
936
|
+
* @returns The details of the requested QR code.
|
|
937
|
+
*/
|
|
938
|
+
async getQrCode(code, qr) {
|
|
939
|
+
if (!this._organizationId) {
|
|
940
|
+
throw new Error("Organization ID is required to get a QR code.");
|
|
941
|
+
}
|
|
942
|
+
const url = this.getUri(this._organizationId, code, "qrs", qr);
|
|
943
|
+
const headers = this.createHeaders(this._apiKey);
|
|
944
|
+
const response = await this.get(url, {
|
|
945
|
+
headers
|
|
946
|
+
});
|
|
947
|
+
if (response.status === 200) {
|
|
948
|
+
const result = response.data;
|
|
949
|
+
if (result.qrCode) {
|
|
950
|
+
const buffer = Buffer2.from(result.qrCode, "base64");
|
|
951
|
+
result.qrCodeBytes = new Uint16Array(buffer);
|
|
952
|
+
}
|
|
953
|
+
return result;
|
|
954
|
+
}
|
|
955
|
+
throw new Error(`Failed to get QR code: ${response.statusText}`);
|
|
956
|
+
}
|
|
957
|
+
async getQrCodes(code, pageNumber, pageSize) {
|
|
958
|
+
if (!this._organizationId) {
|
|
959
|
+
throw new Error("Organization ID is required to get QR codes.");
|
|
960
|
+
}
|
|
961
|
+
const url = this.getUri(this._organizationId, code, "qrs");
|
|
962
|
+
const headers = this.createHeaders(this._apiKey);
|
|
963
|
+
const parameters = {};
|
|
964
|
+
if (pageNumber) {
|
|
965
|
+
parameters.pageNum = pageNumber.toString();
|
|
966
|
+
}
|
|
967
|
+
if (pageSize) {
|
|
968
|
+
parameters.pageSize = pageSize.toString();
|
|
969
|
+
}
|
|
970
|
+
const response = await this.get(url, {
|
|
971
|
+
headers,
|
|
972
|
+
params: parameters
|
|
973
|
+
});
|
|
974
|
+
if (response.status === 200) {
|
|
975
|
+
const result = response.data;
|
|
976
|
+
for (const qrCode of result.data) {
|
|
977
|
+
if (qrCode.qrCode) {
|
|
978
|
+
const buffer = Buffer2.from(qrCode.qrCode, "base64");
|
|
979
|
+
qrCode.qrCodeBytes = new Uint16Array(buffer);
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
return result;
|
|
983
|
+
}
|
|
984
|
+
throw new Error(`Failed to get QR codes: ${response.statusText}`);
|
|
985
|
+
}
|
|
986
|
+
/**
|
|
987
|
+
* Delete a QR code by its ID.
|
|
988
|
+
* @param {string} code The short code associated with the QR code.
|
|
989
|
+
* @param {string} qr The ID of the QR code to delete.
|
|
990
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the QR code was deleted successfully, or false if it was not.
|
|
991
|
+
*/
|
|
992
|
+
async deleteQrCode(code, qr) {
|
|
993
|
+
if (!this._organizationId) {
|
|
994
|
+
throw new Error("Organization ID is required to delete a QR code.");
|
|
995
|
+
}
|
|
996
|
+
const url = this.getUri(this._organizationId, code, "qrs", qr);
|
|
997
|
+
const headers = this.createHeaders(this._apiKey);
|
|
998
|
+
const response = await this.delete(url, {
|
|
999
|
+
headers
|
|
1000
|
+
});
|
|
1001
|
+
if (response.status === 204) {
|
|
1002
|
+
return true;
|
|
1003
|
+
}
|
|
1004
|
+
throw new Error(`Failed to delete QR code: ${response.statusText}`);
|
|
1005
|
+
}
|
|
752
1006
|
};
|
|
753
1007
|
|
|
754
1008
|
// src/hyphen.ts
|
|
@@ -872,5 +1126,6 @@ export {
|
|
|
872
1126
|
Hyphen,
|
|
873
1127
|
Toggle,
|
|
874
1128
|
ToggleHooks,
|
|
1129
|
+
env,
|
|
875
1130
|
loadEnv
|
|
876
1131
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyphen/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.12.0",
|
|
4
4
|
"description": "Hyphen SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -29,26 +29,27 @@
|
|
|
29
29
|
"author": "Team Hyphen <hello@hyphen.ai>",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@swc/core": "^1.
|
|
33
|
-
"@types/node": "^24.0
|
|
32
|
+
"@swc/core": "^1.13.2",
|
|
33
|
+
"@types/node": "^24.1.0",
|
|
34
34
|
"@vitest/coverage-v8": "^3.2.4",
|
|
35
35
|
"rimraf": "^6.0.1",
|
|
36
36
|
"tsd": "^0.32.0",
|
|
37
37
|
"tsup": "^8.5.0",
|
|
38
38
|
"typescript": "^5.8.3",
|
|
39
39
|
"vitest": "^3.2.4",
|
|
40
|
-
"xo": "^1.
|
|
40
|
+
"xo": "^1.2.1"
|
|
41
41
|
},
|
|
42
42
|
"files": [
|
|
43
43
|
"dist",
|
|
44
44
|
"LICENSE"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
+
"@faker-js/faker": "^9.9.0",
|
|
47
48
|
"@hyphen/openfeature-server-provider": "^1.0.7",
|
|
48
49
|
"@openfeature/server-sdk": "^1.18.0",
|
|
49
|
-
"axios": "^1.
|
|
50
|
-
"cacheable": "^1.10.
|
|
51
|
-
"dotenv": "^17.
|
|
50
|
+
"axios": "^1.11.0",
|
|
51
|
+
"cacheable": "^1.10.3",
|
|
52
|
+
"dotenv": "^17.2.1",
|
|
52
53
|
"hookified": "^1.10.0",
|
|
53
54
|
"pino": "^9.7.0"
|
|
54
55
|
}
|