@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 +163 -10
- package/dist/index.cjs +775 -570
- package/dist/index.d.cts +387 -232
- package/dist/index.d.ts +387 -232
- package/dist/index.js +776 -572
- package/package.json +20 -19
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,390 @@
|
|
|
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
|
+
|
|
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>;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type ClickByDay = {
|
|
52
|
+
date: string;
|
|
53
|
+
total: number;
|
|
54
|
+
unique: number;
|
|
55
|
+
};
|
|
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 = {
|
|
87
|
+
/**
|
|
88
|
+
* The short code used for this link. If not provided, a random code will be generated.
|
|
89
|
+
* @default undefined
|
|
90
|
+
*/
|
|
91
|
+
code?: string;
|
|
92
|
+
/**
|
|
93
|
+
* The title of the link. This is used for display purposes.
|
|
94
|
+
* @default undefined
|
|
95
|
+
*/
|
|
96
|
+
title?: string;
|
|
97
|
+
/**
|
|
98
|
+
* The tags associated with the link. This is used for categorization purposes.
|
|
99
|
+
* @default undefined
|
|
100
|
+
*/
|
|
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 = {
|
|
118
|
+
/**
|
|
119
|
+
* The long URL that the short code will redirect to.
|
|
120
|
+
* @default undefined
|
|
121
|
+
*/
|
|
122
|
+
long_url?: string;
|
|
123
|
+
/**
|
|
124
|
+
* The title of the link. This is used for display purposes.
|
|
125
|
+
* @default undefined
|
|
126
|
+
*/
|
|
127
|
+
title?: string;
|
|
128
|
+
/**
|
|
129
|
+
* The tags associated with the link. This is used for categorization purposes.
|
|
130
|
+
* @default undefined
|
|
131
|
+
*/
|
|
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 = {
|
|
147
|
+
/**
|
|
148
|
+
* The title of the QR code. This is used for display purposes.
|
|
149
|
+
* @default undefined
|
|
150
|
+
*/
|
|
151
|
+
title?: string;
|
|
152
|
+
/**
|
|
153
|
+
* The background color of the QR code. This is a hex color code.
|
|
154
|
+
* @default '#ffffff'
|
|
155
|
+
*/
|
|
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;
|
|
172
|
+
};
|
|
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 = {
|
|
187
|
+
/**
|
|
188
|
+
* The URIs to access the link service.
|
|
189
|
+
* @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
|
|
190
|
+
*/
|
|
191
|
+
uris?: string[];
|
|
192
|
+
/**
|
|
193
|
+
* The organization ID to use for the link service.
|
|
194
|
+
* @requires organizationId
|
|
195
|
+
*/
|
|
196
|
+
organizationId?: string;
|
|
197
|
+
/**
|
|
198
|
+
* The API key to use for the link service. This should be provided as the service requires authentication.
|
|
199
|
+
*/
|
|
200
|
+
apiKey?: string;
|
|
201
|
+
} & BaseServiceOptions;
|
|
202
|
+
declare class Link extends BaseService {
|
|
203
|
+
private _uris;
|
|
204
|
+
private _organizationId?;
|
|
205
|
+
private _apiKey?;
|
|
206
|
+
constructor(options?: LinkOptions);
|
|
207
|
+
/**
|
|
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.
|
|
210
|
+
*/
|
|
211
|
+
get uris(): string[];
|
|
212
|
+
/**
|
|
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.
|
|
215
|
+
*/
|
|
216
|
+
set uris(uris: string[]);
|
|
217
|
+
/**
|
|
218
|
+
* Get the organization ID for the link service. This is required to access the link service.
|
|
219
|
+
* @returns {string | undefined} The organization ID.
|
|
220
|
+
*/
|
|
221
|
+
get organizationId(): string | undefined;
|
|
222
|
+
/**
|
|
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.
|
|
225
|
+
*/
|
|
226
|
+
set organizationId(organizationId: string | undefined);
|
|
227
|
+
/**
|
|
228
|
+
* Get the API key for the link service. This is required to access the link service.
|
|
229
|
+
* @returns {string | undefined} The API key.
|
|
230
|
+
*/
|
|
231
|
+
get apiKey(): string | undefined;
|
|
232
|
+
/**
|
|
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.
|
|
235
|
+
*/
|
|
236
|
+
set apiKey(apiKey: string | undefined);
|
|
237
|
+
/**
|
|
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
|
|
241
|
+
*/
|
|
242
|
+
setApiKey(apiKey: string | undefined): void;
|
|
243
|
+
/**
|
|
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.
|
|
248
|
+
*/
|
|
249
|
+
getUri(organizationId: string, prefix1?: string, prefix2?: string, prefix3?: string): string;
|
|
250
|
+
/**
|
|
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.
|
|
256
|
+
*/
|
|
257
|
+
createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
|
|
258
|
+
/**
|
|
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.
|
|
262
|
+
*/
|
|
263
|
+
getShortCode(code: string): Promise<GetShortCodeResponse>;
|
|
264
|
+
/**
|
|
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.
|
|
271
|
+
*/
|
|
272
|
+
getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
|
|
273
|
+
/**
|
|
274
|
+
* Get all tags associated with the organization's short codes.
|
|
275
|
+
* @returns {Promise<string[]>} A promise that resolves to an array of tags.
|
|
276
|
+
*/
|
|
277
|
+
getTags(): Promise<string[]>;
|
|
278
|
+
/**
|
|
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.
|
|
282
|
+
*/
|
|
283
|
+
getCodeStats(code: string, startDate: Date, endDate: Date): Promise<GetCodeStatsResponse>;
|
|
284
|
+
/**
|
|
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.
|
|
289
|
+
*/
|
|
290
|
+
updateShortCode(code: string, options: UpdateShortCodeOptions): Promise<UpdateShortCodeResponse>;
|
|
291
|
+
/**
|
|
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.
|
|
295
|
+
*/
|
|
296
|
+
deleteShortCode(code: string): Promise<boolean>;
|
|
297
|
+
/**
|
|
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.
|
|
302
|
+
*/
|
|
303
|
+
createQrCode(code: string, options?: CreateQrCodeOptions): Promise<CreateQrCodeResponse>;
|
|
304
|
+
/**
|
|
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.
|
|
309
|
+
*/
|
|
310
|
+
getQrCode(code: string, qr: string): Promise<CreateQrCodeResponse>;
|
|
311
|
+
getQrCodes(code: string, pageNumber?: number, pageSize?: number): Promise<GetQrCodesResponse>;
|
|
312
|
+
/**
|
|
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.
|
|
317
|
+
*/
|
|
318
|
+
deleteQrCode(code: string, qr: string): Promise<boolean>;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
type NetInfoOptions = {
|
|
322
|
+
/**
|
|
323
|
+
* API key for authentication. If this is not provided it will try to use `HYPHEN_API_KEY` environment variable.
|
|
324
|
+
* @type {string} - The API key for authentication. This is not the public API key.
|
|
325
|
+
* @default undefined
|
|
326
|
+
*/
|
|
327
|
+
apiKey?: string;
|
|
328
|
+
/**
|
|
329
|
+
* Base URI for the API. If not provided, it will use the default Hyphen API base URI.
|
|
330
|
+
* @type {string} - The base URI for the API.
|
|
331
|
+
* @default 'https://net.info'
|
|
332
|
+
*/
|
|
333
|
+
baseUri?: string;
|
|
334
|
+
} & BaseServiceOptions;
|
|
335
|
+
type ipInfo = {
|
|
336
|
+
ip: string;
|
|
337
|
+
type: string;
|
|
338
|
+
location: {
|
|
339
|
+
country: string;
|
|
340
|
+
region: string;
|
|
341
|
+
city: string;
|
|
342
|
+
lat: number;
|
|
343
|
+
lng: number;
|
|
344
|
+
postalCode: string;
|
|
345
|
+
timezone: string;
|
|
346
|
+
geonameId: number;
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
type ipInfoError = {
|
|
350
|
+
ip: string;
|
|
351
|
+
type: string;
|
|
352
|
+
errorMessage: string;
|
|
353
|
+
};
|
|
354
|
+
declare class NetInfo extends BaseService {
|
|
355
|
+
private _apiKey;
|
|
356
|
+
private _baseUri;
|
|
357
|
+
constructor(options?: NetInfoOptions);
|
|
358
|
+
/**
|
|
359
|
+
* Gets or sets the API key for authentication.
|
|
360
|
+
* If not set, it will try to use the `HYPHEN_API_KEY` environment variable.
|
|
361
|
+
* @type {string | undefined}
|
|
362
|
+
*/
|
|
363
|
+
get apiKey(): string | undefined;
|
|
364
|
+
/**
|
|
365
|
+
* Sets the API key for authentication.
|
|
366
|
+
* @param {string | undefined} value - The API key to set.
|
|
367
|
+
*/
|
|
368
|
+
set apiKey(value: string | undefined);
|
|
369
|
+
/**
|
|
370
|
+
* Gets or sets the base URI for the API.
|
|
371
|
+
* @type {string}
|
|
372
|
+
*/
|
|
373
|
+
get baseUri(): string;
|
|
374
|
+
/**
|
|
375
|
+
* Sets the base URI for the API.
|
|
376
|
+
* @param {string} value - The base URI to set.
|
|
377
|
+
*/
|
|
378
|
+
set baseUri(value: string);
|
|
379
|
+
setApiKey(value: string | undefined): void;
|
|
380
|
+
/**
|
|
381
|
+
* Fetches GeoIP information for a given IP address.
|
|
382
|
+
* @param {string} ip - The IP address to fetch GeoIP information for.
|
|
383
|
+
* @returns {Promise<ipInfo | ipInfoError>} - A promise that resolves to the ip information or an error.
|
|
384
|
+
*/
|
|
385
|
+
getIpInfo(ip: string): Promise<ipInfo | ipInfoError>;
|
|
386
|
+
getIpInfos(ips: string[]): Promise<Array<ipInfo | ipInfoError>>;
|
|
387
|
+
}
|
|
7
388
|
|
|
8
389
|
type ToggleContext = EvaluationContext;
|
|
9
390
|
declare enum ToggleHooks {
|
|
@@ -206,232 +587,6 @@ declare class Toggle extends Hookified {
|
|
|
206
587
|
getObject<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
|
|
207
588
|
}
|
|
208
589
|
|
|
209
|
-
type LoadEnvOptions = {
|
|
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 {LoadEnvOptions} [options] - Options to customize the loading of environment variables.
|
|
218
|
-
* @returns {void}
|
|
219
|
-
* @example
|
|
220
|
-
* import { loadEnv } from '@hyphen/sdk';
|
|
221
|
-
* loadEnv();
|
|
222
|
-
*/
|
|
223
|
-
declare function loadEnv(options?: LoadEnvOptions): void;
|
|
224
|
-
|
|
225
|
-
type BaseServiceOptions = {
|
|
226
|
-
throwErrors?: boolean;
|
|
227
|
-
} & HookifiedOptions;
|
|
228
|
-
declare class BaseService extends Hookified {
|
|
229
|
-
private _log;
|
|
230
|
-
private _cache;
|
|
231
|
-
private _throwErrors;
|
|
232
|
-
constructor(options?: BaseServiceOptions);
|
|
233
|
-
get log(): pino.Logger;
|
|
234
|
-
set log(value: pino.Logger);
|
|
235
|
-
get cache(): Cacheable;
|
|
236
|
-
set cache(value: Cacheable);
|
|
237
|
-
get throwErrors(): boolean;
|
|
238
|
-
set throwErrors(value: boolean);
|
|
239
|
-
error(message: string, ...args: any[]): void;
|
|
240
|
-
warn(message: string, ...args: any[]): void;
|
|
241
|
-
info(message: string, ...args: any[]): void;
|
|
242
|
-
get<T>(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
243
|
-
post<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
244
|
-
put<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
245
|
-
delete<T>(url: string, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
246
|
-
patch<T>(url: string, data: any, config?: AxiosRequestConfig): Promise<axios.AxiosResponse<T, any>>;
|
|
247
|
-
createHeaders(apiKey?: string): Record<string, string>;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
type NetInfoOptions = {
|
|
251
|
-
/**
|
|
252
|
-
* API key for authentication. If this is not provided it will try to use `HYPHEN_API_KEY` environment variable.
|
|
253
|
-
* @type {string} - The API key for authentication. This is not the public API key.
|
|
254
|
-
* @default undefined
|
|
255
|
-
*/
|
|
256
|
-
apiKey?: string;
|
|
257
|
-
/**
|
|
258
|
-
* Base URI for the API. If not provided, it will use the default Hyphen API base URI.
|
|
259
|
-
* @type {string} - The base URI for the API.
|
|
260
|
-
* @default 'https://net.info'
|
|
261
|
-
*/
|
|
262
|
-
baseUri?: string;
|
|
263
|
-
} & BaseServiceOptions;
|
|
264
|
-
type ipInfo = {
|
|
265
|
-
ip: string;
|
|
266
|
-
type: string;
|
|
267
|
-
location: {
|
|
268
|
-
country: string;
|
|
269
|
-
region: string;
|
|
270
|
-
city: string;
|
|
271
|
-
lat: number;
|
|
272
|
-
lng: number;
|
|
273
|
-
postalCode: string;
|
|
274
|
-
timezone: string;
|
|
275
|
-
geonameId: number;
|
|
276
|
-
};
|
|
277
|
-
};
|
|
278
|
-
type ipInfoError = {
|
|
279
|
-
ip: string;
|
|
280
|
-
type: string;
|
|
281
|
-
errorMessage: string;
|
|
282
|
-
};
|
|
283
|
-
declare class NetInfo extends BaseService {
|
|
284
|
-
private _apiKey;
|
|
285
|
-
private _baseUri;
|
|
286
|
-
constructor(options?: NetInfoOptions);
|
|
287
|
-
/**
|
|
288
|
-
* Gets or sets the API key for authentication.
|
|
289
|
-
* If not set, it will try to use the `HYPHEN_API_KEY` environment variable.
|
|
290
|
-
* @type {string | undefined}
|
|
291
|
-
*/
|
|
292
|
-
get apiKey(): string | undefined;
|
|
293
|
-
/**
|
|
294
|
-
* Sets the API key for authentication.
|
|
295
|
-
* @param {string | undefined} value - The API key to set.
|
|
296
|
-
*/
|
|
297
|
-
set apiKey(value: string | undefined);
|
|
298
|
-
/**
|
|
299
|
-
* Gets or sets the base URI for the API.
|
|
300
|
-
* @type {string}
|
|
301
|
-
*/
|
|
302
|
-
get baseUri(): string;
|
|
303
|
-
/**
|
|
304
|
-
* Sets the base URI for the API.
|
|
305
|
-
* @param {string} value - The base URI to set.
|
|
306
|
-
*/
|
|
307
|
-
set baseUri(value: string);
|
|
308
|
-
setApiKey(value: string | undefined): void;
|
|
309
|
-
/**
|
|
310
|
-
* Fetches GeoIP information for a given IP address.
|
|
311
|
-
* @param {string} ip - The IP address to fetch GeoIP information for.
|
|
312
|
-
* @returns {Promise<ipInfo | ipInfoError>} - A promise that resolves to the ip information or an error.
|
|
313
|
-
*/
|
|
314
|
-
getIpInfo(ip: string): Promise<ipInfo | ipInfoError>;
|
|
315
|
-
getIpInfos(ips: string[]): Promise<Array<ipInfo | ipInfoError>>;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
type CreateShortCodeOptions = {
|
|
319
|
-
/**
|
|
320
|
-
* The short code used for this link. If not provided, a random code will be generated.
|
|
321
|
-
* @default undefined
|
|
322
|
-
*/
|
|
323
|
-
code?: string;
|
|
324
|
-
/**
|
|
325
|
-
* The title of the link. This is used for display purposes.
|
|
326
|
-
* @default undefined
|
|
327
|
-
*/
|
|
328
|
-
title?: string;
|
|
329
|
-
/**
|
|
330
|
-
* The tags associated with the link. This is used for categorization purposes.
|
|
331
|
-
* @default undefined
|
|
332
|
-
*/
|
|
333
|
-
tags?: string[];
|
|
334
|
-
};
|
|
335
|
-
type CreateShortCodeResponse = {
|
|
336
|
-
id: string;
|
|
337
|
-
code: string;
|
|
338
|
-
long_url: string;
|
|
339
|
-
domain: string;
|
|
340
|
-
createdAt: string;
|
|
341
|
-
title?: string;
|
|
342
|
-
tags?: string[];
|
|
343
|
-
organizationId: {
|
|
344
|
-
id: string;
|
|
345
|
-
name: string;
|
|
346
|
-
};
|
|
347
|
-
};
|
|
348
|
-
type GetShortCodesResponse = {
|
|
349
|
-
total: number;
|
|
350
|
-
pageNum: number;
|
|
351
|
-
pageSize: number;
|
|
352
|
-
data: GetShortCodeResponse[];
|
|
353
|
-
};
|
|
354
|
-
type GetShortCodeResponse = CreateShortCodeResponse;
|
|
355
|
-
type LinkOptions = {
|
|
356
|
-
/**
|
|
357
|
-
* The URIs to access the link service.
|
|
358
|
-
* @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
|
|
359
|
-
*/
|
|
360
|
-
uris?: string[];
|
|
361
|
-
/**
|
|
362
|
-
* The organization ID to use for the link service.
|
|
363
|
-
* @requires organizationId
|
|
364
|
-
*/
|
|
365
|
-
organizationId?: string;
|
|
366
|
-
/**
|
|
367
|
-
* The API key to use for the link service. This should be provided as the service requires authentication.
|
|
368
|
-
*/
|
|
369
|
-
apiKey?: string;
|
|
370
|
-
} & BaseServiceOptions;
|
|
371
|
-
declare class Link extends BaseService {
|
|
372
|
-
private _uris;
|
|
373
|
-
private _organizationId?;
|
|
374
|
-
private _apiKey?;
|
|
375
|
-
constructor(options?: LinkOptions);
|
|
376
|
-
/**
|
|
377
|
-
* Get the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
378
|
-
* @returns {string[]} The URIs for the link service.
|
|
379
|
-
*/
|
|
380
|
-
get uris(): string[];
|
|
381
|
-
/**
|
|
382
|
-
* Set the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
383
|
-
* @param {string[]} uris - The URIs to set.
|
|
384
|
-
*/
|
|
385
|
-
set uris(uris: string[]);
|
|
386
|
-
/**
|
|
387
|
-
* Get the organization ID for the link service. This is required to access the link service.
|
|
388
|
-
* @returns {string | undefined} The organization ID.
|
|
389
|
-
*/
|
|
390
|
-
get organizationId(): string | undefined;
|
|
391
|
-
/**
|
|
392
|
-
* Set the organization ID for the link service. This is required to access the link service.
|
|
393
|
-
* @param {string | undefined} organizationId - The organization ID to set.
|
|
394
|
-
*/
|
|
395
|
-
set organizationId(organizationId: string | undefined);
|
|
396
|
-
/**
|
|
397
|
-
* Get the API key for the link service. This is required to access the link service.
|
|
398
|
-
* @returns {string | undefined} The API key.
|
|
399
|
-
*/
|
|
400
|
-
get apiKey(): string | undefined;
|
|
401
|
-
/**
|
|
402
|
-
* Set the API key for the link service. This is required to access the link service.
|
|
403
|
-
* @param {string | undefined} apiKey - The API key to set.
|
|
404
|
-
*/
|
|
405
|
-
set apiKey(apiKey: string | undefined);
|
|
406
|
-
/**
|
|
407
|
-
* Set the API key for the link service. If the API key starts with 'public_', an error is thrown.
|
|
408
|
-
* This is to ensure that the API key is not a public key, which should not be used for authenticated requests.
|
|
409
|
-
* @param {string} apiKey
|
|
410
|
-
*/
|
|
411
|
-
setApiKey(apiKey: string | undefined): void;
|
|
412
|
-
/**
|
|
413
|
-
* Get the URI for a specific organization and code. This is used internally to construct the URI for the link service.
|
|
414
|
-
* @param {string} organizationId The ID of the organization.
|
|
415
|
-
* @param {string} code The code to include in the URI.
|
|
416
|
-
* @returns {string} The constructed URI.
|
|
417
|
-
*/
|
|
418
|
-
getUri(organizationId: string, code?: string): string;
|
|
419
|
-
createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
|
|
420
|
-
/**
|
|
421
|
-
* Get a short code by its code.
|
|
422
|
-
* @param {string} code The short code to retrieve. Example: 'code_686bed403c3991bd676bba4d'
|
|
423
|
-
* @returns {Promise<GetShortCodeResponse>} A promise that resolves to the short code details.
|
|
424
|
-
*/
|
|
425
|
-
getShortCode(code: string): Promise<GetShortCodeResponse>;
|
|
426
|
-
getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
|
|
427
|
-
/**
|
|
428
|
-
* Delete a short code.
|
|
429
|
-
* @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
|
|
430
|
-
* @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
|
|
431
|
-
*/
|
|
432
|
-
deleteShortCode(code: string): Promise<boolean>;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
590
|
type HyphenOptions = {
|
|
436
591
|
/**
|
|
437
592
|
* The public API key to use for the Hyphen service.
|
|
@@ -455,21 +610,21 @@ type HyphenOptions = {
|
|
|
455
610
|
* @see ToggleOptions
|
|
456
611
|
* @default {Toggle}
|
|
457
612
|
*/
|
|
458
|
-
toggle?: Omit<ToggleOptions,
|
|
613
|
+
toggle?: Omit<ToggleOptions, "publicApiKey" | "throwErrors">;
|
|
459
614
|
/**
|
|
460
615
|
* Options for the NetInfo service.
|
|
461
616
|
* Excludes apiKey and throwErrors from NetInfoOptions.
|
|
462
617
|
* @see NetInfoOptions
|
|
463
618
|
* @default {NetInfo}
|
|
464
619
|
*/
|
|
465
|
-
netInfo?: Omit<NetInfoOptions,
|
|
620
|
+
netInfo?: Omit<NetInfoOptions, "apiKey" | "throwErrors">;
|
|
466
621
|
/**
|
|
467
622
|
* Options for the Link service.
|
|
468
623
|
* Excludes apiKey and throwErrors from LinkOptions.
|
|
469
624
|
* @see LinkOptions
|
|
470
625
|
* @default {Link}
|
|
471
626
|
*/
|
|
472
|
-
link?: Omit<LinkOptions,
|
|
627
|
+
link?: Omit<LinkOptions, "apiKey" | "throwErrors">;
|
|
473
628
|
} & HookifiedOptions;
|
|
474
629
|
declare class Hyphen extends Hookified {
|
|
475
630
|
private readonly _netInfo;
|
|
@@ -531,4 +686,4 @@ declare class Hyphen extends Hookified {
|
|
|
531
686
|
set throwErrors(value: boolean);
|
|
532
687
|
}
|
|
533
688
|
|
|
534
|
-
export { Hyphen, type HyphenOptions, Toggle, type ToggleCachingOptions, type ToggleContext, type ToggleGetOptions, ToggleHooks, type ToggleOptions, loadEnv };
|
|
689
|
+
export { type EnvOptions, Hyphen, type HyphenOptions, type LoadEnvOptions, Toggle, type ToggleCachingOptions, type ToggleContext, type ToggleGetOptions, ToggleHooks, type ToggleOptions, env, loadEnv };
|