@hyphen/sdk 2.2.0 → 3.0.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 +49 -0
- package/dist/index.cjs +0 -13
- package/dist/index.d.cts +4 -15
- package/dist/index.d.ts +4 -15
- package/dist/index.js +0 -13
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@ The Hyphen Node.js SDK is a JavaScript library that allows developers to easily
|
|
|
36
36
|
- [Creating a QR Code from a Short Code](#creating-a-qr-code-from-a-short-code)
|
|
37
37
|
- [Get QR Codes for a Short Code](#get-qr-codes-for-a-short-code)
|
|
38
38
|
- [Deleting a QR Code](#deleting-a-qr-code)
|
|
39
|
+
- [Migrating to v3](#migrating-to-v3)
|
|
39
40
|
- [Contributing](#contributing)
|
|
40
41
|
- [Testing Your Changes](#testing-your-changes)
|
|
41
42
|
- [License and Copyright](#license-and-copyright)
|
|
@@ -958,6 +959,54 @@ const response = await link.deleteQrCode(code, qr);
|
|
|
958
959
|
console.log('Delete QR Code Response:', response);
|
|
959
960
|
```
|
|
960
961
|
|
|
962
|
+
# Migrating to v3
|
|
963
|
+
|
|
964
|
+
v3 upgrades the underlying event system to [hookified v2](https://hookified.org). There are two breaking changes:
|
|
965
|
+
|
|
966
|
+
## `throwOnEmptyListeners` now defaults to `true`
|
|
967
|
+
|
|
968
|
+
In v2, emitting events (`error`) without any registered listeners was silently ignored. In v3, this will throw an error by default. If your code emits events, you must register listeners:
|
|
969
|
+
|
|
970
|
+
```typescript
|
|
971
|
+
const hyphen = new Hyphen({ apiKey: 'your-key' });
|
|
972
|
+
|
|
973
|
+
// Register listeners before triggering operations that emit events
|
|
974
|
+
hyphen.on('error', (message) => {
|
|
975
|
+
console.error('Error:', message);
|
|
976
|
+
});
|
|
977
|
+
```
|
|
978
|
+
|
|
979
|
+
If you want to restore the previous behavior where unhandled events are silently ignored, pass `throwOnEmptyListeners: false` in the options:
|
|
980
|
+
|
|
981
|
+
```typescript
|
|
982
|
+
const hyphen = new Hyphen({
|
|
983
|
+
apiKey: 'your-key',
|
|
984
|
+
throwOnEmptyListeners: false,
|
|
985
|
+
});
|
|
986
|
+
|
|
987
|
+
const toggle = new Toggle({
|
|
988
|
+
publicApiKey: 'public_your-key',
|
|
989
|
+
throwOnEmptyListeners: false,
|
|
990
|
+
});
|
|
991
|
+
```
|
|
992
|
+
|
|
993
|
+
## `throwErrors` option removed
|
|
994
|
+
|
|
995
|
+
The `throwErrors` option has been removed from `BaseServiceOptions`, `HyphenOptions`, and all service classes. Error throwing is now handled natively by hookified v2.
|
|
996
|
+
|
|
997
|
+
To get the previous `throwErrors: true` behavior, use `throwOnEmitError: true` instead:
|
|
998
|
+
|
|
999
|
+
```typescript
|
|
1000
|
+
// v2 (old)
|
|
1001
|
+
const netInfo = new NetInfo({ throwErrors: true });
|
|
1002
|
+
|
|
1003
|
+
// v3 (new)
|
|
1004
|
+
const netInfo = new NetInfo({ throwOnEmitError: true });
|
|
1005
|
+
```
|
|
1006
|
+
|
|
1007
|
+
The `throwErrors` getter/setter on service instances has also been removed as you can use `.throwOnEmitError` getter/setter now.
|
|
1008
|
+
|
|
1009
|
+
|
|
961
1010
|
# Contributing
|
|
962
1011
|
|
|
963
1012
|
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
|
@@ -132,13 +132,9 @@ var BaseService = class extends import_hookified.Hookified {
|
|
|
132
132
|
}
|
|
133
133
|
_log = (0, import_pino.default)();
|
|
134
134
|
_cache = new import_cacheable.Cacheable();
|
|
135
|
-
_throwErrors = false;
|
|
136
135
|
_net;
|
|
137
136
|
constructor(options) {
|
|
138
137
|
super(options);
|
|
139
|
-
if (options && options.throwErrors !== void 0) {
|
|
140
|
-
this._throwErrors = options.throwErrors;
|
|
141
|
-
}
|
|
142
138
|
this._net = new import_net2.CacheableNet({
|
|
143
139
|
cache: this._cache
|
|
144
140
|
});
|
|
@@ -156,18 +152,9 @@ var BaseService = class extends import_hookified.Hookified {
|
|
|
156
152
|
this._cache = value;
|
|
157
153
|
this._net.cache = value;
|
|
158
154
|
}
|
|
159
|
-
get throwErrors() {
|
|
160
|
-
return this._throwErrors;
|
|
161
|
-
}
|
|
162
|
-
set throwErrors(value) {
|
|
163
|
-
this._throwErrors = value;
|
|
164
|
-
}
|
|
165
155
|
error(message, ...args) {
|
|
166
156
|
this._log.error(message, ...args);
|
|
167
157
|
this.emit("error", message, ...args);
|
|
168
|
-
if (this.throwErrors) {
|
|
169
|
-
throw new Error(message);
|
|
170
|
-
}
|
|
171
158
|
}
|
|
172
159
|
warn(message, ...args) {
|
|
173
160
|
this._log.warn(message, ...args);
|
package/dist/index.d.cts
CHANGED
|
@@ -107,21 +107,16 @@ interface HttpResponse<T = any> {
|
|
|
107
107
|
config: any;
|
|
108
108
|
request?: any;
|
|
109
109
|
}
|
|
110
|
-
type BaseServiceOptions =
|
|
111
|
-
throwErrors?: boolean;
|
|
112
|
-
} & HookifiedOptions;
|
|
110
|
+
type BaseServiceOptions = HookifiedOptions;
|
|
113
111
|
declare class BaseService extends Hookified {
|
|
114
112
|
private _log;
|
|
115
113
|
private _cache;
|
|
116
|
-
private _throwErrors;
|
|
117
114
|
private _net;
|
|
118
115
|
constructor(options?: BaseServiceOptions);
|
|
119
116
|
get log(): pino.Logger;
|
|
120
117
|
set log(value: pino.Logger);
|
|
121
118
|
get cache(): Cacheable;
|
|
122
119
|
set cache(value: Cacheable);
|
|
123
|
-
get throwErrors(): boolean;
|
|
124
|
-
set throwErrors(value: boolean);
|
|
125
120
|
error(message: string, ...args: any[]): void;
|
|
126
121
|
warn(message: string, ...args: any[]): void;
|
|
127
122
|
info(message: string, ...args: any[]): void;
|
|
@@ -1051,29 +1046,23 @@ type HyphenOptions = {
|
|
|
1051
1046
|
* This is used for authenticated endpoints that require an API key.
|
|
1052
1047
|
*/
|
|
1053
1048
|
apiKey?: string;
|
|
1054
|
-
/**
|
|
1055
|
-
* Whether to throw errors or not.
|
|
1056
|
-
* If set to true, errors will be thrown instead of logged.
|
|
1057
|
-
* @default false
|
|
1058
|
-
*/
|
|
1059
|
-
throwErrors?: boolean;
|
|
1060
1049
|
/**
|
|
1061
1050
|
* Options for the Toggle service.
|
|
1062
|
-
* Excludes publicApiKey
|
|
1051
|
+
* Excludes `publicApiKey` as it's provided at the top level.
|
|
1063
1052
|
* @see ToggleOptions
|
|
1064
1053
|
* @default {Toggle}
|
|
1065
1054
|
*/
|
|
1066
1055
|
toggle?: Omit<ToggleOptions, "publicApiKey">;
|
|
1067
1056
|
/**
|
|
1068
1057
|
* Options for the NetInfo service.
|
|
1069
|
-
* Excludes apiKey
|
|
1058
|
+
* Excludes `apiKey` as it's provided at the top level.
|
|
1070
1059
|
* @see NetInfoOptions
|
|
1071
1060
|
* @default {NetInfo}
|
|
1072
1061
|
*/
|
|
1073
1062
|
netInfo?: Omit<NetInfoOptions, "apiKey">;
|
|
1074
1063
|
/**
|
|
1075
1064
|
* Options for the Link service.
|
|
1076
|
-
* Excludes apiKey
|
|
1065
|
+
* Excludes `apiKey` as it's provided at the top level.
|
|
1077
1066
|
* @see LinkOptions
|
|
1078
1067
|
* @default {Link}
|
|
1079
1068
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -107,21 +107,16 @@ interface HttpResponse<T = any> {
|
|
|
107
107
|
config: any;
|
|
108
108
|
request?: any;
|
|
109
109
|
}
|
|
110
|
-
type BaseServiceOptions =
|
|
111
|
-
throwErrors?: boolean;
|
|
112
|
-
} & HookifiedOptions;
|
|
110
|
+
type BaseServiceOptions = HookifiedOptions;
|
|
113
111
|
declare class BaseService extends Hookified {
|
|
114
112
|
private _log;
|
|
115
113
|
private _cache;
|
|
116
|
-
private _throwErrors;
|
|
117
114
|
private _net;
|
|
118
115
|
constructor(options?: BaseServiceOptions);
|
|
119
116
|
get log(): pino.Logger;
|
|
120
117
|
set log(value: pino.Logger);
|
|
121
118
|
get cache(): Cacheable;
|
|
122
119
|
set cache(value: Cacheable);
|
|
123
|
-
get throwErrors(): boolean;
|
|
124
|
-
set throwErrors(value: boolean);
|
|
125
120
|
error(message: string, ...args: any[]): void;
|
|
126
121
|
warn(message: string, ...args: any[]): void;
|
|
127
122
|
info(message: string, ...args: any[]): void;
|
|
@@ -1051,29 +1046,23 @@ type HyphenOptions = {
|
|
|
1051
1046
|
* This is used for authenticated endpoints that require an API key.
|
|
1052
1047
|
*/
|
|
1053
1048
|
apiKey?: string;
|
|
1054
|
-
/**
|
|
1055
|
-
* Whether to throw errors or not.
|
|
1056
|
-
* If set to true, errors will be thrown instead of logged.
|
|
1057
|
-
* @default false
|
|
1058
|
-
*/
|
|
1059
|
-
throwErrors?: boolean;
|
|
1060
1049
|
/**
|
|
1061
1050
|
* Options for the Toggle service.
|
|
1062
|
-
* Excludes publicApiKey
|
|
1051
|
+
* Excludes `publicApiKey` as it's provided at the top level.
|
|
1063
1052
|
* @see ToggleOptions
|
|
1064
1053
|
* @default {Toggle}
|
|
1065
1054
|
*/
|
|
1066
1055
|
toggle?: Omit<ToggleOptions, "publicApiKey">;
|
|
1067
1056
|
/**
|
|
1068
1057
|
* Options for the NetInfo service.
|
|
1069
|
-
* Excludes apiKey
|
|
1058
|
+
* Excludes `apiKey` as it's provided at the top level.
|
|
1070
1059
|
* @see NetInfoOptions
|
|
1071
1060
|
* @default {NetInfo}
|
|
1072
1061
|
*/
|
|
1073
1062
|
netInfo?: Omit<NetInfoOptions, "apiKey">;
|
|
1074
1063
|
/**
|
|
1075
1064
|
* Options for the Link service.
|
|
1076
|
-
* Excludes apiKey
|
|
1065
|
+
* Excludes `apiKey` as it's provided at the top level.
|
|
1077
1066
|
* @see LinkOptions
|
|
1078
1067
|
* @default {Link}
|
|
1079
1068
|
*/
|
package/dist/index.js
CHANGED
|
@@ -94,13 +94,9 @@ var BaseService = class extends Hookified {
|
|
|
94
94
|
}
|
|
95
95
|
_log = pino();
|
|
96
96
|
_cache = new Cacheable();
|
|
97
|
-
_throwErrors = false;
|
|
98
97
|
_net;
|
|
99
98
|
constructor(options) {
|
|
100
99
|
super(options);
|
|
101
|
-
if (options && options.throwErrors !== void 0) {
|
|
102
|
-
this._throwErrors = options.throwErrors;
|
|
103
|
-
}
|
|
104
100
|
this._net = new CacheableNet2({
|
|
105
101
|
cache: this._cache
|
|
106
102
|
});
|
|
@@ -118,18 +114,9 @@ var BaseService = class extends Hookified {
|
|
|
118
114
|
this._cache = value;
|
|
119
115
|
this._net.cache = value;
|
|
120
116
|
}
|
|
121
|
-
get throwErrors() {
|
|
122
|
-
return this._throwErrors;
|
|
123
|
-
}
|
|
124
|
-
set throwErrors(value) {
|
|
125
|
-
this._throwErrors = value;
|
|
126
|
-
}
|
|
127
117
|
error(message, ...args) {
|
|
128
118
|
this._log.error(message, ...args);
|
|
129
119
|
this.emit("error", message, ...args);
|
|
130
|
-
if (this.throwErrors) {
|
|
131
|
-
throw new Error(message);
|
|
132
|
-
}
|
|
133
120
|
}
|
|
134
121
|
warn(message, ...args) {
|
|
135
122
|
this._log.warn(message, ...args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyphen/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "Hyphen SDK for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -33,25 +33,25 @@
|
|
|
33
33
|
"node": ">=20.12.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@biomejs/biome": "^2.3.
|
|
37
|
-
"@swc/core": "^1.15.
|
|
38
|
-
"@types/node": "^25.
|
|
39
|
-
"@vitest/coverage-v8": "^4.0.
|
|
40
|
-
"rimraf": "^6.1.
|
|
36
|
+
"@biomejs/biome": "^2.3.14",
|
|
37
|
+
"@swc/core": "^1.15.18",
|
|
38
|
+
"@types/node": "^25.3.3",
|
|
39
|
+
"@vitest/coverage-v8": "^4.0.18",
|
|
40
|
+
"rimraf": "^6.1.3",
|
|
41
41
|
"tsd": "^0.33.0",
|
|
42
42
|
"tsup": "^8.5.1",
|
|
43
43
|
"typescript": "^5.9.3",
|
|
44
|
-
"vitest": "^4.0.
|
|
44
|
+
"vitest": "^4.0.18"
|
|
45
45
|
},
|
|
46
46
|
"files": [
|
|
47
47
|
"dist",
|
|
48
48
|
"LICENSE"
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@cacheable/net": "^2.0.
|
|
52
|
-
"@faker-js/faker": "^10.
|
|
53
|
-
"cacheable": "^2.3.
|
|
54
|
-
"hookified": "^
|
|
55
|
-
"pino": "^10.
|
|
51
|
+
"@cacheable/net": "^2.0.6",
|
|
52
|
+
"@faker-js/faker": "^10.3.0",
|
|
53
|
+
"cacheable": "^2.3.3",
|
|
54
|
+
"hookified": "^2.0.1",
|
|
55
|
+
"pino": "^10.3.1"
|
|
56
56
|
}
|
|
57
57
|
}
|