@hyphen/sdk 1.12.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 +1 -0
- package/dist/index.cjs +748 -741
- package/dist/index.d.cts +394 -394
- package/dist/index.d.ts +394 -394
- package/dist/index.js +747 -740
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,252 +1,321 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EvaluationContext, Client } from '@openfeature/server-sdk';
|
|
1
|
+
import { HookifiedOptions, Hookified } from 'hookified';
|
|
3
2
|
import * as axios from 'axios';
|
|
4
3
|
import { AxiosRequestConfig } from 'axios';
|
|
5
4
|
import { Cacheable } from 'cacheable';
|
|
6
5
|
import pino from 'pino';
|
|
6
|
+
import { EvaluationContext, Client } from '@openfeature/server-sdk';
|
|
7
7
|
|
|
8
|
-
type
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
8
|
+
type EnvOptions = {
|
|
9
|
+
path?: string;
|
|
10
|
+
environment?: string;
|
|
11
|
+
local?: boolean;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* @description Helper function to load your environment variables based on your default .env file
|
|
15
|
+
* and the current environment.
|
|
16
|
+
* @param {EnvOptions} [options] - Options to customize the loading of environment variables.
|
|
17
|
+
* @returns {void}
|
|
18
|
+
* @example
|
|
19
|
+
* import { env } from '@hyphen/sdk';
|
|
20
|
+
* env();
|
|
21
|
+
*/
|
|
22
|
+
declare function env(options?: EnvOptions): void;
|
|
23
|
+
declare const loadEnv: typeof env;
|
|
24
|
+
type LoadEnvOptions = EnvOptions;
|
|
25
|
+
|
|
26
|
+
type BaseServiceOptions = {
|
|
27
|
+
throwErrors?: boolean;
|
|
28
|
+
} & HookifiedOptions;
|
|
29
|
+
declare class BaseService extends Hookified {
|
|
30
|
+
private _log;
|
|
31
|
+
private _cache;
|
|
32
|
+
private _throwErrors;
|
|
33
|
+
constructor(options?: BaseServiceOptions);
|
|
34
|
+
get log(): pino.Logger;
|
|
35
|
+
set log(value: pino.Logger);
|
|
36
|
+
get cache(): Cacheable;
|
|
37
|
+
set cache(value: Cacheable);
|
|
38
|
+
get throwErrors(): boolean;
|
|
39
|
+
set throwErrors(value: boolean);
|
|
40
|
+
error(message: string, ...args: any[]): void;
|
|
41
|
+
warn(message: string, ...args: any[]): void;
|
|
42
|
+
info(message: string, ...args: any[]): void;
|
|
43
|
+
get<T>(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
44
|
+
post<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
45
|
+
put<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
46
|
+
delete<T>(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
47
|
+
patch<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
48
|
+
createHeaders(apiKey?: string): Record<string, string>;
|
|
18
49
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
50
|
+
|
|
51
|
+
type ClickByDay = {
|
|
52
|
+
date: string;
|
|
53
|
+
total: number;
|
|
54
|
+
unique: number;
|
|
22
55
|
};
|
|
23
|
-
type
|
|
56
|
+
type Clicks = {
|
|
57
|
+
total: number;
|
|
58
|
+
unique: number;
|
|
59
|
+
byDay: ClickByDay[];
|
|
60
|
+
};
|
|
61
|
+
type Referral = {
|
|
62
|
+
url: string;
|
|
63
|
+
total: number;
|
|
64
|
+
};
|
|
65
|
+
type Browser = {
|
|
66
|
+
name: string;
|
|
67
|
+
total: number;
|
|
68
|
+
};
|
|
69
|
+
type Device = {
|
|
70
|
+
name: string;
|
|
71
|
+
total: number;
|
|
72
|
+
};
|
|
73
|
+
type Location = {
|
|
74
|
+
country: string;
|
|
75
|
+
total: number;
|
|
76
|
+
unique: number;
|
|
77
|
+
};
|
|
78
|
+
type GetCodeStatsResponse = {
|
|
79
|
+
clicks: Clicks;
|
|
80
|
+
referrals: Referral[];
|
|
81
|
+
browsers: Browser[];
|
|
82
|
+
devices: Device[];
|
|
83
|
+
locations: Location[];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
type CreateShortCodeOptions = {
|
|
24
87
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
88
|
+
* The short code used for this link. If not provided, a random code will be generated.
|
|
89
|
+
* @default undefined
|
|
27
90
|
*/
|
|
28
|
-
|
|
91
|
+
code?: string;
|
|
29
92
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
93
|
+
* The title of the link. This is used for display purposes.
|
|
94
|
+
* @default undefined
|
|
32
95
|
*/
|
|
33
|
-
|
|
96
|
+
title?: string;
|
|
34
97
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
37
|
-
* @example production
|
|
98
|
+
* The tags associated with the link. This is used for categorization purposes.
|
|
99
|
+
* @default undefined
|
|
38
100
|
*/
|
|
39
|
-
|
|
101
|
+
tags?: string[];
|
|
102
|
+
};
|
|
103
|
+
type CreateShortCodeResponse = {
|
|
104
|
+
id: string;
|
|
105
|
+
code: string;
|
|
106
|
+
long_url: string;
|
|
107
|
+
domain: string;
|
|
108
|
+
createdAt: string;
|
|
109
|
+
title?: string;
|
|
110
|
+
tags?: string[];
|
|
111
|
+
organizationId: {
|
|
112
|
+
id: string;
|
|
113
|
+
name: string;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
type UpdateShortCodeResponse = CreateShortCodeResponse;
|
|
117
|
+
type UpdateShortCodeOptions = {
|
|
40
118
|
/**
|
|
41
|
-
* The
|
|
42
|
-
* @
|
|
119
|
+
* The long URL that the short code will redirect to.
|
|
120
|
+
* @default undefined
|
|
43
121
|
*/
|
|
44
|
-
|
|
122
|
+
long_url?: string;
|
|
45
123
|
/**
|
|
46
|
-
*
|
|
47
|
-
* @
|
|
124
|
+
* The title of the link. This is used for display purposes.
|
|
125
|
+
* @default undefined
|
|
48
126
|
*/
|
|
49
|
-
|
|
127
|
+
title?: string;
|
|
50
128
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @
|
|
53
|
-
* @default false
|
|
129
|
+
* The tags associated with the link. This is used for categorization purposes.
|
|
130
|
+
* @default undefined
|
|
54
131
|
*/
|
|
55
|
-
|
|
132
|
+
tags?: string[];
|
|
133
|
+
};
|
|
134
|
+
type GetShortCodesResponse = {
|
|
135
|
+
total: number;
|
|
136
|
+
pageNum: number;
|
|
137
|
+
pageSize: number;
|
|
138
|
+
data: GetShortCodeResponse[];
|
|
139
|
+
};
|
|
140
|
+
type GetShortCodeResponse = CreateShortCodeResponse;
|
|
141
|
+
declare enum QrSize {
|
|
142
|
+
SMALL = "small",
|
|
143
|
+
MEDIUM = "medium",
|
|
144
|
+
LARGE = "large"
|
|
145
|
+
}
|
|
146
|
+
type CreateQrCodeOptions = {
|
|
56
147
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @type {Array<string>}
|
|
60
|
-
* @example ['https://toggle.hyphen.ai']
|
|
148
|
+
* The title of the QR code. This is used for display purposes.
|
|
149
|
+
* @default undefined
|
|
61
150
|
*/
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
type ToggleGetOptions = {
|
|
151
|
+
title?: string;
|
|
65
152
|
/**
|
|
66
|
-
* The
|
|
67
|
-
* @
|
|
153
|
+
* The background color of the QR code. This is a hex color code.
|
|
154
|
+
* @default '#ffffff'
|
|
68
155
|
*/
|
|
69
|
-
|
|
156
|
+
backgroundColor?: string;
|
|
157
|
+
/**
|
|
158
|
+
* The color of the QR code. This is a hex color code.
|
|
159
|
+
* @default '#000000'
|
|
160
|
+
*/
|
|
161
|
+
color?: string;
|
|
162
|
+
/**
|
|
163
|
+
* The size of the QR code. This can be 'small', 'medium', or 'large'.
|
|
164
|
+
* @default QrSize.MEDIUM
|
|
165
|
+
*/
|
|
166
|
+
size?: QrSize;
|
|
167
|
+
/**
|
|
168
|
+
* The logo to include in the QR code. This should be a base64 encoded string.
|
|
169
|
+
* @default undefined
|
|
170
|
+
*/
|
|
171
|
+
logo?: string;
|
|
70
172
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
173
|
+
type CreateQrCodeResponse = {
|
|
174
|
+
id: string;
|
|
175
|
+
title?: string;
|
|
176
|
+
qrCode: string;
|
|
177
|
+
qrCodeBytes: Uint16Array;
|
|
178
|
+
qrLink: string;
|
|
179
|
+
};
|
|
180
|
+
type GetQrCodesResponse = {
|
|
181
|
+
total: number;
|
|
182
|
+
pageNum: number;
|
|
183
|
+
pageSize: number;
|
|
184
|
+
data: CreateQrCodeResponse[];
|
|
185
|
+
};
|
|
186
|
+
type LinkOptions = {
|
|
81
187
|
/**
|
|
82
|
-
*
|
|
83
|
-
* @
|
|
188
|
+
* The URIs to access the link service.
|
|
189
|
+
* @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
|
|
84
190
|
*/
|
|
85
|
-
|
|
191
|
+
uris?: string[];
|
|
86
192
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @
|
|
193
|
+
* The organization ID to use for the link service.
|
|
194
|
+
* @requires organizationId
|
|
89
195
|
*/
|
|
90
|
-
|
|
196
|
+
organizationId?: string;
|
|
91
197
|
/**
|
|
92
|
-
*
|
|
93
|
-
* @returns {string}
|
|
198
|
+
* The API key to use for the link service. This should be provided as the service requires authentication.
|
|
94
199
|
*/
|
|
95
|
-
|
|
200
|
+
apiKey?: string;
|
|
201
|
+
} & BaseServiceOptions;
|
|
202
|
+
declare class Link extends BaseService {
|
|
203
|
+
private _uris;
|
|
204
|
+
private _organizationId?;
|
|
205
|
+
private _apiKey?;
|
|
206
|
+
constructor(options?: LinkOptions);
|
|
96
207
|
/**
|
|
97
|
-
*
|
|
98
|
-
* @
|
|
208
|
+
* Get the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
209
|
+
* @returns {string[]} The URIs for the link service.
|
|
99
210
|
*/
|
|
100
|
-
|
|
211
|
+
get uris(): string[];
|
|
101
212
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @
|
|
213
|
+
* Set the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
214
|
+
* @param {string[]} uris - The URIs to set.
|
|
104
215
|
*/
|
|
105
|
-
|
|
216
|
+
set uris(uris: string[]);
|
|
106
217
|
/**
|
|
107
|
-
*
|
|
108
|
-
* @
|
|
218
|
+
* Get the organization ID for the link service. This is required to access the link service.
|
|
219
|
+
* @returns {string | undefined} The organization ID.
|
|
109
220
|
*/
|
|
110
|
-
|
|
221
|
+
get organizationId(): string | undefined;
|
|
111
222
|
/**
|
|
112
|
-
*
|
|
113
|
-
* @
|
|
223
|
+
* Set the organization ID for the link service. This is required to access the link service.
|
|
224
|
+
* @param {string | undefined} organizationId - The organization ID to set.
|
|
114
225
|
*/
|
|
115
|
-
|
|
226
|
+
set organizationId(organizationId: string | undefined);
|
|
116
227
|
/**
|
|
117
|
-
*
|
|
118
|
-
* @
|
|
228
|
+
* Get the API key for the link service. This is required to access the link service.
|
|
229
|
+
* @returns {string | undefined} The API key.
|
|
119
230
|
*/
|
|
120
|
-
|
|
231
|
+
get apiKey(): string | undefined;
|
|
121
232
|
/**
|
|
122
|
-
*
|
|
123
|
-
* @
|
|
233
|
+
* Set the API key for the link service. This is required to access the link service.
|
|
234
|
+
* @param {string | undefined} apiKey - The API key to set.
|
|
124
235
|
*/
|
|
125
|
-
|
|
236
|
+
set apiKey(apiKey: string | undefined);
|
|
126
237
|
/**
|
|
127
|
-
* Set the
|
|
128
|
-
*
|
|
238
|
+
* Set the API key for the link service. If the API key starts with 'public_', an error is thrown.
|
|
239
|
+
* This is to ensure that the API key is not a public key, which should not be used for authenticated requests.
|
|
240
|
+
* @param {string} apiKey
|
|
129
241
|
*/
|
|
130
|
-
|
|
242
|
+
setApiKey(apiKey: string | undefined): void;
|
|
131
243
|
/**
|
|
132
|
-
* Get the
|
|
133
|
-
* @
|
|
244
|
+
* Get the URI for a specific organization and code. This is used internally to construct the URI for the link service.
|
|
245
|
+
* @param {string} organizationId The ID of the organization.
|
|
246
|
+
* @param {string} code The code to include in the URI.
|
|
247
|
+
* @returns {string} The constructed URI.
|
|
134
248
|
*/
|
|
135
|
-
|
|
249
|
+
getUri(organizationId: string, prefix1?: string, prefix2?: string, prefix3?: string): string;
|
|
136
250
|
/**
|
|
137
|
-
*
|
|
138
|
-
* @param {
|
|
251
|
+
* Create a short code for a long URL.
|
|
252
|
+
* @param {string} longUrl The long URL to shorten.
|
|
253
|
+
* @param {string} domain The domain to use for the short code.
|
|
254
|
+
* @param {CreateShortCodeOptions} options Optional parameters for creating the short code.
|
|
255
|
+
* @returns {Promise<CreateShortCodeResponse>} A promise that resolves to the created short code details.
|
|
139
256
|
*/
|
|
140
|
-
|
|
257
|
+
createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
|
|
141
258
|
/**
|
|
142
|
-
* Get
|
|
143
|
-
* @
|
|
259
|
+
* Get a short code by its code.
|
|
260
|
+
* @param {string} code The short code to retrieve. Example: 'code_686bed403c3991bd676bba4d'
|
|
261
|
+
* @returns {Promise<GetShortCodeResponse>} A promise that resolves to the short code details.
|
|
144
262
|
*/
|
|
145
|
-
|
|
263
|
+
getShortCode(code: string): Promise<GetShortCodeResponse>;
|
|
146
264
|
/**
|
|
147
|
-
*
|
|
148
|
-
* @param {
|
|
265
|
+
* Get all short codes for the organization.
|
|
266
|
+
* @param {string} titleSearch Optional search term to filter short codes by title.
|
|
267
|
+
* @param {string[]} tags Optional tags to filter short codes.
|
|
268
|
+
* @param {number} pageNumber The page number to retrieve. Default is 1.
|
|
269
|
+
* @param {number} pageSize The number of short codes per page. Default is 100.
|
|
270
|
+
* @returns {Promise<GetShortCodesResponse>} A promise that resolves to the list of short codes.
|
|
149
271
|
*/
|
|
150
|
-
|
|
272
|
+
getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
|
|
151
273
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* it will emit an error and console warning and not set the key. Used by the constructor and publicApiKey setter.
|
|
155
|
-
* @param key
|
|
156
|
-
* @returns
|
|
274
|
+
* Get all tags associated with the organization's short codes.
|
|
275
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of tags.
|
|
157
276
|
*/
|
|
158
|
-
|
|
277
|
+
getTags(): Promise<string[]>;
|
|
159
278
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @param
|
|
279
|
+
* Get statistics for a specific short code.
|
|
280
|
+
* @param code The short code to retrieve statistics for.
|
|
281
|
+
* @returns {Promise<GetCodeStatsResponse>} A promise that resolves to the code statistics.
|
|
162
282
|
*/
|
|
163
|
-
|
|
283
|
+
getCodeStats(code: string, startDate: Date, endDate: Date): Promise<GetCodeStatsResponse>;
|
|
164
284
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
* @returns {Promise<
|
|
285
|
+
* Update a short code.
|
|
286
|
+
* @param {string} code The short code to update. Example: 'code_686bed403c3991bd676bba4d'
|
|
287
|
+
* @param {UpdateShortCodeOptions} options The options to update the short code with.
|
|
288
|
+
* @returns {Promise<UpdateShortCodeResponse>} A promise that resolves to the updated short code details.
|
|
169
289
|
*/
|
|
170
|
-
|
|
290
|
+
updateShortCode(code: string, options: UpdateShortCodeOptions): Promise<UpdateShortCodeResponse>;
|
|
171
291
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* @
|
|
175
|
-
* @param {T} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
|
|
176
|
-
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
177
|
-
* @returns {Promise<T>}
|
|
292
|
+
* Delete a short code.
|
|
293
|
+
* @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
|
|
294
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
|
|
178
295
|
*/
|
|
179
|
-
|
|
296
|
+
deleteShortCode(code: string): Promise<boolean>;
|
|
180
297
|
/**
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @param {
|
|
184
|
-
* @
|
|
185
|
-
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
186
|
-
* @returns {Promise<boolean>} - The value of the feature flag
|
|
298
|
+
* Create a QR code for a specific short code.
|
|
299
|
+
* @param {string} code The short code to create a QR code for.
|
|
300
|
+
* @param {CreateQrCodeOptions} options The options for creating the QR code.
|
|
301
|
+
* @returns {Promise<CreateQrCodeResponse>} A promise that resolves to the created QR code details.
|
|
187
302
|
*/
|
|
188
|
-
|
|
303
|
+
createQrCode(code: string, options?: CreateQrCodeOptions): Promise<CreateQrCodeResponse>;
|
|
189
304
|
/**
|
|
190
|
-
* Get a
|
|
191
|
-
* @param
|
|
192
|
-
* @param
|
|
193
|
-
* @
|
|
194
|
-
* @returns {Promise<string>} - The value of the feature flag
|
|
305
|
+
* Get a QR code by its ID.
|
|
306
|
+
* @param code The short code associated with the QR code.
|
|
307
|
+
* @param qr The ID of the QR code to retrieve.
|
|
308
|
+
* @returns The details of the requested QR code.
|
|
195
309
|
*/
|
|
196
|
-
|
|
197
|
-
|
|
310
|
+
getQrCode(code: string, qr: string): Promise<CreateQrCodeResponse>;
|
|
311
|
+
getQrCodes(code: string, pageNumber?: number, pageSize?: number): Promise<GetQrCodesResponse>;
|
|
198
312
|
/**
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
* @param {string}
|
|
202
|
-
* @
|
|
203
|
-
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
204
|
-
* @returns {Promise<T>} - The value of the feature flag
|
|
313
|
+
* Delete a QR code by its ID.
|
|
314
|
+
* @param {string} code The short code associated with the QR code.
|
|
315
|
+
* @param {string} qr The ID of the QR code to delete.
|
|
316
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the QR code was deleted successfully, or false if it was not.
|
|
205
317
|
*/
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
type EnvOptions = {
|
|
210
|
-
path?: string;
|
|
211
|
-
environment?: string;
|
|
212
|
-
local?: boolean;
|
|
213
|
-
};
|
|
214
|
-
/**
|
|
215
|
-
* @description Helper function to load your environment variables based on your default .env file
|
|
216
|
-
* and the current environment.
|
|
217
|
-
* @param {EnvOptions} [options] - Options to customize the loading of environment variables.
|
|
218
|
-
* @returns {void}
|
|
219
|
-
* @example
|
|
220
|
-
* import { env } from '@hyphen/sdk';
|
|
221
|
-
* env();
|
|
222
|
-
*/
|
|
223
|
-
declare function env(options?: EnvOptions): void;
|
|
224
|
-
declare const loadEnv: typeof env;
|
|
225
|
-
type LoadEnvOptions = EnvOptions;
|
|
226
|
-
|
|
227
|
-
type BaseServiceOptions = {
|
|
228
|
-
throwErrors?: boolean;
|
|
229
|
-
} & HookifiedOptions;
|
|
230
|
-
declare class BaseService extends Hookified {
|
|
231
|
-
private _log;
|
|
232
|
-
private _cache;
|
|
233
|
-
private _throwErrors;
|
|
234
|
-
constructor(options?: BaseServiceOptions);
|
|
235
|
-
get log(): pino.Logger;
|
|
236
|
-
set log(value: pino.Logger);
|
|
237
|
-
get cache(): Cacheable;
|
|
238
|
-
set cache(value: Cacheable);
|
|
239
|
-
get throwErrors(): boolean;
|
|
240
|
-
set throwErrors(value: boolean);
|
|
241
|
-
error(message: string, ...args: any[]): void;
|
|
242
|
-
warn(message: string, ...args: any[]): void;
|
|
243
|
-
info(message: string, ...args: any[]): void;
|
|
244
|
-
get<T>(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
245
|
-
post<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
246
|
-
put<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
247
|
-
delete<T>(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
248
|
-
patch<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
249
|
-
createHeaders(apiKey?: string): Record<string, string>;
|
|
318
|
+
deleteQrCode(code: string, qr: string): Promise<boolean>;
|
|
250
319
|
}
|
|
251
320
|
|
|
252
321
|
type NetInfoOptions = {
|
|
@@ -317,274 +386,205 @@ declare class NetInfo extends BaseService {
|
|
|
317
386
|
getIpInfos(ips: string[]): Promise<Array<ipInfo | ipInfoError>>;
|
|
318
387
|
}
|
|
319
388
|
|
|
320
|
-
type
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
type Browser = {
|
|
335
|
-
name: string;
|
|
336
|
-
total: number;
|
|
337
|
-
};
|
|
338
|
-
type Device = {
|
|
339
|
-
name: string;
|
|
340
|
-
total: number;
|
|
341
|
-
};
|
|
342
|
-
type Location = {
|
|
343
|
-
country: string;
|
|
344
|
-
total: number;
|
|
345
|
-
unique: number;
|
|
346
|
-
};
|
|
347
|
-
type GetCodeStatsResponse = {
|
|
348
|
-
clicks: Clicks;
|
|
349
|
-
referrals: Referral[];
|
|
350
|
-
browsers: Browser[];
|
|
351
|
-
devices: Device[];
|
|
352
|
-
locations: Location[];
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
type CreateShortCodeOptions = {
|
|
356
|
-
/**
|
|
357
|
-
* The short code used for this link. If not provided, a random code will be generated.
|
|
358
|
-
* @default undefined
|
|
359
|
-
*/
|
|
360
|
-
code?: string;
|
|
361
|
-
/**
|
|
362
|
-
* The title of the link. This is used for display purposes.
|
|
363
|
-
* @default undefined
|
|
364
|
-
*/
|
|
365
|
-
title?: string;
|
|
366
|
-
/**
|
|
367
|
-
* The tags associated with the link. This is used for categorization purposes.
|
|
368
|
-
* @default undefined
|
|
369
|
-
*/
|
|
370
|
-
tags?: string[];
|
|
371
|
-
};
|
|
372
|
-
type CreateShortCodeResponse = {
|
|
373
|
-
id: string;
|
|
374
|
-
code: string;
|
|
375
|
-
long_url: string;
|
|
376
|
-
domain: string;
|
|
377
|
-
createdAt: string;
|
|
378
|
-
title?: string;
|
|
379
|
-
tags?: string[];
|
|
380
|
-
organizationId: {
|
|
381
|
-
id: string;
|
|
382
|
-
name: string;
|
|
383
|
-
};
|
|
389
|
+
type ToggleContext = EvaluationContext;
|
|
390
|
+
declare enum ToggleHooks {
|
|
391
|
+
beforeGetBoolean = "beforeGetBoolean",
|
|
392
|
+
afterGetBoolean = "afterGetBoolean",
|
|
393
|
+
beforeGetString = "beforeGetString",
|
|
394
|
+
afterGetString = "afterGetString",
|
|
395
|
+
beforeGetNumber = "beforeGetNumber",
|
|
396
|
+
afterGetNumber = "afterGetNumber",
|
|
397
|
+
beforeGetObject = "beforeGetObject",
|
|
398
|
+
afterGetObject = "afterGetObject"
|
|
399
|
+
}
|
|
400
|
+
type ToggleCachingOptions = {
|
|
401
|
+
ttl?: number;
|
|
402
|
+
generateCacheKeyFn?: (context?: ToggleContext) => string;
|
|
384
403
|
};
|
|
385
|
-
type
|
|
386
|
-
type UpdateShortCodeOptions = {
|
|
404
|
+
type ToggleOptions = {
|
|
387
405
|
/**
|
|
388
|
-
*
|
|
389
|
-
* @
|
|
406
|
+
* Your application name. If this is not set it will look for the HYPHEN_APPLICATION_ID environment variable.
|
|
407
|
+
* @type {string}
|
|
390
408
|
*/
|
|
391
|
-
|
|
409
|
+
applicationId?: string;
|
|
392
410
|
/**
|
|
393
|
-
*
|
|
394
|
-
* @
|
|
411
|
+
* Your Hyphen Public API key. If this is not set it will look for the HYPHEN_PUBLIC_API_KEY environment variable.
|
|
412
|
+
* @type {string}
|
|
395
413
|
*/
|
|
396
|
-
|
|
414
|
+
publicApiKey?: string;
|
|
397
415
|
/**
|
|
398
|
-
*
|
|
399
|
-
* @
|
|
416
|
+
* Your environment name such as development, production. Default is what is set at NODE_ENV
|
|
417
|
+
* @type {string}
|
|
418
|
+
* @example production
|
|
400
419
|
*/
|
|
401
|
-
|
|
402
|
-
};
|
|
403
|
-
type GetShortCodesResponse = {
|
|
404
|
-
total: number;
|
|
405
|
-
pageNum: number;
|
|
406
|
-
pageSize: number;
|
|
407
|
-
data: GetShortCodeResponse[];
|
|
408
|
-
};
|
|
409
|
-
type GetShortCodeResponse = CreateShortCodeResponse;
|
|
410
|
-
declare enum QrSize {
|
|
411
|
-
SMALL = "small",
|
|
412
|
-
MEDIUM = "medium",
|
|
413
|
-
LARGE = "large"
|
|
414
|
-
}
|
|
415
|
-
type CreateQrCodeOptions = {
|
|
420
|
+
environment?: string;
|
|
416
421
|
/**
|
|
417
|
-
* The
|
|
418
|
-
* @
|
|
422
|
+
* The context to use for evaluating feature flags
|
|
423
|
+
* @type {ToggleContext}
|
|
419
424
|
*/
|
|
420
|
-
|
|
425
|
+
context?: ToggleContext;
|
|
421
426
|
/**
|
|
422
|
-
*
|
|
423
|
-
* @
|
|
427
|
+
* Cache options to use for the request
|
|
428
|
+
* @type {ToggleCachingOptions}
|
|
424
429
|
*/
|
|
425
|
-
|
|
430
|
+
caching?: ToggleCachingOptions;
|
|
426
431
|
/**
|
|
427
|
-
*
|
|
428
|
-
* @
|
|
432
|
+
* Throw errors in addition to emitting them
|
|
433
|
+
* @type {boolean}
|
|
434
|
+
* @default false
|
|
429
435
|
*/
|
|
430
|
-
|
|
436
|
+
throwErrors?: boolean;
|
|
431
437
|
/**
|
|
432
|
-
*
|
|
433
|
-
*
|
|
438
|
+
* Horizon URIs to use for talking to Toggle. You can use this to override
|
|
439
|
+
* the default URIs for testin or if you are using a self-hosted version.
|
|
440
|
+
* @type {Array<string>}
|
|
441
|
+
* @example ['https://toggle.hyphen.ai']
|
|
434
442
|
*/
|
|
435
|
-
|
|
443
|
+
uris?: string[];
|
|
444
|
+
};
|
|
445
|
+
type ToggleGetOptions = {
|
|
436
446
|
/**
|
|
437
|
-
* The
|
|
438
|
-
* @
|
|
447
|
+
* The context to use for evaluating feature flags
|
|
448
|
+
* @type {ToggleContext}
|
|
439
449
|
*/
|
|
440
|
-
|
|
441
|
-
};
|
|
442
|
-
type CreateQrCodeResponse = {
|
|
443
|
-
id: string;
|
|
444
|
-
title?: string;
|
|
445
|
-
qrCode: string;
|
|
446
|
-
qrCodeBytes: Uint16Array;
|
|
447
|
-
qrLink: string;
|
|
448
|
-
};
|
|
449
|
-
type GetQrCodesResponse = {
|
|
450
|
-
total: number;
|
|
451
|
-
pageNum: number;
|
|
452
|
-
pageSize: number;
|
|
453
|
-
data: CreateQrCodeResponse[];
|
|
450
|
+
context?: ToggleContext;
|
|
454
451
|
};
|
|
455
|
-
|
|
452
|
+
declare class Toggle extends Hookified {
|
|
453
|
+
private _applicationId;
|
|
454
|
+
private _publicApiKey;
|
|
455
|
+
private _environment;
|
|
456
|
+
private _client;
|
|
457
|
+
private _context;
|
|
458
|
+
private _throwErrors;
|
|
459
|
+
private _uris;
|
|
460
|
+
private _caching;
|
|
461
|
+
constructor(options?: ToggleOptions);
|
|
456
462
|
/**
|
|
457
|
-
*
|
|
458
|
-
* @
|
|
463
|
+
* Get the application ID
|
|
464
|
+
* @returns {string | undefined}
|
|
459
465
|
*/
|
|
460
|
-
|
|
466
|
+
get applicationId(): string | undefined;
|
|
461
467
|
/**
|
|
462
|
-
*
|
|
463
|
-
* @
|
|
468
|
+
* Set the application ID
|
|
469
|
+
* @param {string | undefined} value
|
|
464
470
|
*/
|
|
465
|
-
|
|
471
|
+
set applicationId(value: string | undefined);
|
|
466
472
|
/**
|
|
467
|
-
*
|
|
473
|
+
* Get the public API key
|
|
474
|
+
* @returns {string}
|
|
468
475
|
*/
|
|
469
|
-
|
|
470
|
-
} & BaseServiceOptions;
|
|
471
|
-
declare class Link extends BaseService {
|
|
472
|
-
private _uris;
|
|
473
|
-
private _organizationId?;
|
|
474
|
-
private _apiKey?;
|
|
475
|
-
constructor(options?: LinkOptions);
|
|
476
|
+
get publicApiKey(): string | undefined;
|
|
476
477
|
/**
|
|
477
|
-
*
|
|
478
|
-
* @
|
|
478
|
+
* Set the public API key
|
|
479
|
+
* @param {string} value
|
|
479
480
|
*/
|
|
480
|
-
|
|
481
|
+
set publicApiKey(value: string | undefined);
|
|
481
482
|
/**
|
|
482
|
-
*
|
|
483
|
-
* @
|
|
483
|
+
* Get the environment
|
|
484
|
+
* @returns {string}
|
|
484
485
|
*/
|
|
485
|
-
|
|
486
|
+
get environment(): string;
|
|
486
487
|
/**
|
|
487
|
-
*
|
|
488
|
-
* @
|
|
488
|
+
* Set the environment
|
|
489
|
+
* @param {string} value
|
|
489
490
|
*/
|
|
490
|
-
|
|
491
|
+
set environment(value: string);
|
|
491
492
|
/**
|
|
492
|
-
*
|
|
493
|
-
* @
|
|
493
|
+
* Get the throwErrors. If true, errors will be thrown in addition to being emitted.
|
|
494
|
+
* @returns {boolean}
|
|
494
495
|
*/
|
|
495
|
-
|
|
496
|
+
get throwErrors(): boolean;
|
|
496
497
|
/**
|
|
497
|
-
*
|
|
498
|
-
* @
|
|
498
|
+
* Set the throwErrors. If true, errors will be thrown in addition to being emitted.
|
|
499
|
+
* @param {boolean} value
|
|
499
500
|
*/
|
|
500
|
-
|
|
501
|
+
set throwErrors(value: boolean);
|
|
501
502
|
/**
|
|
502
|
-
*
|
|
503
|
-
* @
|
|
503
|
+
* Get the current context. This is the default context used. You can override this at the get function level.
|
|
504
|
+
* @returns {ToggleContext}
|
|
504
505
|
*/
|
|
505
|
-
|
|
506
|
+
get context(): ToggleContext | undefined;
|
|
506
507
|
/**
|
|
507
|
-
* Set the
|
|
508
|
-
*
|
|
509
|
-
* @param {string} apiKey
|
|
508
|
+
* Set the context. This is the default context used. You can override this at the get function level.
|
|
509
|
+
* @param {ToggleContext} value
|
|
510
510
|
*/
|
|
511
|
-
|
|
511
|
+
set context(value: ToggleContext | undefined);
|
|
512
512
|
/**
|
|
513
|
-
* Get the
|
|
514
|
-
* @
|
|
515
|
-
* @param {string} code The code to include in the URI.
|
|
516
|
-
* @returns {string} The constructed URI.
|
|
513
|
+
* Get the URIs. This is used to override the default URIs for testing or if you are using a self-hosted version.
|
|
514
|
+
* @returns {Array<string>}
|
|
517
515
|
*/
|
|
518
|
-
|
|
516
|
+
get uris(): string[] | undefined;
|
|
519
517
|
/**
|
|
520
|
-
*
|
|
521
|
-
* @param {string}
|
|
522
|
-
* @param {string} domain The domain to use for the short code.
|
|
523
|
-
* @param {CreateShortCodeOptions} options Optional parameters for creating the short code.
|
|
524
|
-
* @returns {Promise<CreateShortCodeResponse>} A promise that resolves to the created short code details.
|
|
518
|
+
* Set the URIs. This is used to override the default URIs for testing or if you are using a self-hosted version.
|
|
519
|
+
* @param {Array<string>} value
|
|
525
520
|
*/
|
|
526
|
-
|
|
521
|
+
set uris(value: string[] | undefined);
|
|
527
522
|
/**
|
|
528
|
-
* Get
|
|
529
|
-
* @
|
|
530
|
-
* @returns {Promise<GetShortCodeResponse>} A promise that resolves to the short code details.
|
|
523
|
+
* Get the caching options.
|
|
524
|
+
* @returns {ToggleCachingOptions | undefined}
|
|
531
525
|
*/
|
|
532
|
-
|
|
526
|
+
get caching(): ToggleCachingOptions | undefined;
|
|
533
527
|
/**
|
|
534
|
-
*
|
|
535
|
-
* @param {
|
|
536
|
-
* @param {string[]} tags Optional tags to filter short codes.
|
|
537
|
-
* @param {number} pageNumber The page number to retrieve. Default is 1.
|
|
538
|
-
* @param {number} pageSize The number of short codes per page. Default is 100.
|
|
539
|
-
* @returns {Promise<GetShortCodesResponse>} A promise that resolves to the list of short codes.
|
|
528
|
+
* Set the caching options.
|
|
529
|
+
* @param {ToggleCachingOptions | undefined} value
|
|
540
530
|
*/
|
|
541
|
-
|
|
531
|
+
set caching(value: ToggleCachingOptions | undefined);
|
|
542
532
|
/**
|
|
543
|
-
*
|
|
544
|
-
*
|
|
533
|
+
* This is a helper function to set the public API key. It will check if the key starts with public_ and set it. If it
|
|
534
|
+
* does set it will also set the client to undefined to force a new one to be created. If it does not,
|
|
535
|
+
* it will emit an error and console warning and not set the key. Used by the constructor and publicApiKey setter.
|
|
536
|
+
* @param key
|
|
537
|
+
* @returns
|
|
545
538
|
*/
|
|
546
|
-
|
|
539
|
+
setPublicApiKey(key: string): void;
|
|
547
540
|
/**
|
|
548
|
-
*
|
|
549
|
-
* @param
|
|
550
|
-
* @returns {Promise<GetCodeStatsResponse>} A promise that resolves to the code statistics.
|
|
541
|
+
* Set the context. This is the default context used. You can override this at the get function level.
|
|
542
|
+
* @param {ToggleContext} context
|
|
551
543
|
*/
|
|
552
|
-
|
|
544
|
+
setContext(context: ToggleContext): void;
|
|
553
545
|
/**
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* @returns {Promise<
|
|
546
|
+
* Helper function to get the client. This will create a new client if one does not exist. It will also set the
|
|
547
|
+
* application ID, environment, and URIs if they are not set. This is used by the get function to get the client.
|
|
548
|
+
* This is normally only used internally.
|
|
549
|
+
* @returns {Promise<Client>}
|
|
558
550
|
*/
|
|
559
|
-
|
|
551
|
+
getClient(): Promise<Client>;
|
|
560
552
|
/**
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* @
|
|
553
|
+
* This is the main function to get a feature flag value. It will check the type of the default value and call the
|
|
554
|
+
* appropriate function. It will also set the context if it is not set.
|
|
555
|
+
* @param {string} key - The key of the feature flag
|
|
556
|
+
* @param {T} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
|
|
557
|
+
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
558
|
+
* @returns {Promise<T>}
|
|
564
559
|
*/
|
|
565
|
-
|
|
560
|
+
get<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
|
|
566
561
|
/**
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
* @param {
|
|
570
|
-
* @
|
|
562
|
+
* Get a boolean value from the feature flag. This will check the type of the default value and call the
|
|
563
|
+
* appropriate function. It will also set the context if it is not set.
|
|
564
|
+
* @param {string} key - The key of the feature flag
|
|
565
|
+
* @param {boolean} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
|
|
566
|
+
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
567
|
+
* @returns {Promise<boolean>} - The value of the feature flag
|
|
571
568
|
*/
|
|
572
|
-
|
|
569
|
+
getBoolean(key: string, defaultValue: boolean, options?: ToggleGetOptions): Promise<boolean>;
|
|
573
570
|
/**
|
|
574
|
-
* Get a
|
|
575
|
-
* @param
|
|
576
|
-
* @param
|
|
577
|
-
* @
|
|
571
|
+
* Get a string value from the feature flag.
|
|
572
|
+
* @param {string} key - The key of the feature flag
|
|
573
|
+
* @param {string} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
|
|
574
|
+
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
575
|
+
* @returns {Promise<string>} - The value of the feature flag
|
|
578
576
|
*/
|
|
579
|
-
|
|
580
|
-
|
|
577
|
+
getString(key: string, defaultValue: string, options?: ToggleGetOptions): Promise<string>;
|
|
578
|
+
getNumber(key: string, defaultValue: number, options?: ToggleGetOptions): Promise<number>;
|
|
581
579
|
/**
|
|
582
|
-
*
|
|
583
|
-
*
|
|
584
|
-
* @param {string}
|
|
585
|
-
* @
|
|
580
|
+
* Get an object value from the feature flag. This will check the type of the default value and call the
|
|
581
|
+
* appropriate function. It will also set the context if it is not set.
|
|
582
|
+
* @param {string} key - The key of the feature flag
|
|
583
|
+
* @param {T} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
|
|
584
|
+
* @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
|
|
585
|
+
* @returns {Promise<T>} - The value of the feature flag
|
|
586
586
|
*/
|
|
587
|
-
|
|
587
|
+
getObject<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
|
|
588
588
|
}
|
|
589
589
|
|
|
590
590
|
type HyphenOptions = {
|
|
@@ -610,21 +610,21 @@ type HyphenOptions = {
|
|
|
610
610
|
* @see ToggleOptions
|
|
611
611
|
* @default {Toggle}
|
|
612
612
|
*/
|
|
613
|
-
toggle?: Omit<ToggleOptions,
|
|
613
|
+
toggle?: Omit<ToggleOptions, "publicApiKey" | "throwErrors">;
|
|
614
614
|
/**
|
|
615
615
|
* Options for the NetInfo service.
|
|
616
616
|
* Excludes apiKey and throwErrors from NetInfoOptions.
|
|
617
617
|
* @see NetInfoOptions
|
|
618
618
|
* @default {NetInfo}
|
|
619
619
|
*/
|
|
620
|
-
netInfo?: Omit<NetInfoOptions,
|
|
620
|
+
netInfo?: Omit<NetInfoOptions, "apiKey" | "throwErrors">;
|
|
621
621
|
/**
|
|
622
622
|
* Options for the Link service.
|
|
623
623
|
* Excludes apiKey and throwErrors from LinkOptions.
|
|
624
624
|
* @see LinkOptions
|
|
625
625
|
* @default {Link}
|
|
626
626
|
*/
|
|
627
|
-
link?: Omit<LinkOptions,
|
|
627
|
+
link?: Omit<LinkOptions, "apiKey" | "throwErrors">;
|
|
628
628
|
} & HookifiedOptions;
|
|
629
629
|
declare class Hyphen extends Hookified {
|
|
630
630
|
private readonly _netInfo;
|