@hyphen/sdk 1.8.0 → 1.10.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 +137 -10
- package/dist/index.cjs +464 -0
- package/dist/index.d.cts +294 -2
- package/dist/index.d.ts +294 -2
- package/dist/index.js +463 -0
- package/package.json +9 -9
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Hookified } from 'hookified';
|
|
1
|
+
import { Hookified, HookifiedOptions } from 'hookified';
|
|
2
2
|
import { EvaluationContext, Client } from '@openfeature/server-sdk';
|
|
3
|
+
import * as axios from 'axios';
|
|
4
|
+
import { AxiosRequestConfig } from 'axios';
|
|
5
|
+
import { Cacheable } from 'cacheable';
|
|
6
|
+
import pino from 'pino';
|
|
3
7
|
|
|
4
8
|
type ToggleContext = EvaluationContext;
|
|
5
9
|
declare enum ToggleHooks {
|
|
@@ -218,4 +222,292 @@ type LoadEnvOptions = {
|
|
|
218
222
|
*/
|
|
219
223
|
declare function loadEnv(options?: LoadEnvOptions): void;
|
|
220
224
|
|
|
221
|
-
|
|
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 LinkOptions = {
|
|
349
|
+
/**
|
|
350
|
+
* The URIs to access the link service.
|
|
351
|
+
* @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
|
|
352
|
+
*/
|
|
353
|
+
uris?: string[];
|
|
354
|
+
/**
|
|
355
|
+
* The organization ID to use for the link service.
|
|
356
|
+
* @requires organizationId
|
|
357
|
+
*/
|
|
358
|
+
organizationId?: string;
|
|
359
|
+
/**
|
|
360
|
+
* The API key to use for the link service. This should be provided as the service requires authentication.
|
|
361
|
+
*/
|
|
362
|
+
apiKey?: string;
|
|
363
|
+
} & BaseServiceOptions;
|
|
364
|
+
declare class Link extends BaseService {
|
|
365
|
+
private _uris;
|
|
366
|
+
private _organizationId?;
|
|
367
|
+
private _apiKey?;
|
|
368
|
+
constructor(options?: LinkOptions);
|
|
369
|
+
/**
|
|
370
|
+
* Get the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
371
|
+
* @returns {string[]} The URIs for the link service.
|
|
372
|
+
*/
|
|
373
|
+
get uris(): string[];
|
|
374
|
+
/**
|
|
375
|
+
* Set the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
376
|
+
* @param {string[]} uris - The URIs to set.
|
|
377
|
+
*/
|
|
378
|
+
set uris(uris: string[]);
|
|
379
|
+
/**
|
|
380
|
+
* Get the organization ID for the link service. This is required to access the link service.
|
|
381
|
+
* @returns {string | undefined} The organization ID.
|
|
382
|
+
*/
|
|
383
|
+
get organizationId(): string | undefined;
|
|
384
|
+
/**
|
|
385
|
+
* Set the organization ID for the link service. This is required to access the link service.
|
|
386
|
+
* @param {string | undefined} organizationId - The organization ID to set.
|
|
387
|
+
*/
|
|
388
|
+
set organizationId(organizationId: string | undefined);
|
|
389
|
+
/**
|
|
390
|
+
* Get the API key for the link service. This is required to access the link service.
|
|
391
|
+
* @returns {string | undefined} The API key.
|
|
392
|
+
*/
|
|
393
|
+
get apiKey(): string | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* Set the API key for the link service. This is required to access the link service.
|
|
396
|
+
* @param {string | undefined} apiKey - The API key to set.
|
|
397
|
+
*/
|
|
398
|
+
set apiKey(apiKey: string | undefined);
|
|
399
|
+
/**
|
|
400
|
+
* Set the API key for the link service. If the API key starts with 'public_', an error is thrown.
|
|
401
|
+
* This is to ensure that the API key is not a public key, which should not be used for authenticated requests.
|
|
402
|
+
* @param {string} apiKey
|
|
403
|
+
*/
|
|
404
|
+
setApiKey(apiKey: string | undefined): void;
|
|
405
|
+
createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
|
|
406
|
+
/**
|
|
407
|
+
* Delete a short code.
|
|
408
|
+
* @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
|
|
409
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
|
|
410
|
+
*/
|
|
411
|
+
deleteShortCode(code: string): Promise<boolean>;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
type HyphenOptions = {
|
|
415
|
+
/**
|
|
416
|
+
* The public API key to use for the Hyphen service.
|
|
417
|
+
* This is used for public endpoints that do not require authentication.
|
|
418
|
+
*/
|
|
419
|
+
publicApiKey?: string;
|
|
420
|
+
/**
|
|
421
|
+
* The API key to use for the Hyphen service.
|
|
422
|
+
* This is used for authenticated endpoints that require an API key.
|
|
423
|
+
*/
|
|
424
|
+
apiKey?: string;
|
|
425
|
+
/**
|
|
426
|
+
* Whether to throw errors or not.
|
|
427
|
+
* If set to true, errors will be thrown instead of logged.
|
|
428
|
+
* @default false
|
|
429
|
+
*/
|
|
430
|
+
throwErrors?: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* Options for the Toggle service.
|
|
433
|
+
* Excludes publicApiKey and throwErrors from ToggleOptions.
|
|
434
|
+
* @see ToggleOptions
|
|
435
|
+
* @default {Toggle}
|
|
436
|
+
*/
|
|
437
|
+
toggle?: Omit<ToggleOptions, 'publicApiKey' | 'throwErrors'>;
|
|
438
|
+
/**
|
|
439
|
+
* Options for the NetInfo service.
|
|
440
|
+
* Excludes apiKey and throwErrors from NetInfoOptions.
|
|
441
|
+
* @see NetInfoOptions
|
|
442
|
+
* @default {NetInfo}
|
|
443
|
+
*/
|
|
444
|
+
netInfo?: Omit<NetInfoOptions, 'apiKey' | 'throwErrors'>;
|
|
445
|
+
/**
|
|
446
|
+
* Options for the Link service.
|
|
447
|
+
* Excludes apiKey and throwErrors from LinkOptions.
|
|
448
|
+
* @see LinkOptions
|
|
449
|
+
* @default {Link}
|
|
450
|
+
*/
|
|
451
|
+
link?: Omit<LinkOptions, 'apiKey' | 'throwErrors'>;
|
|
452
|
+
} & HookifiedOptions;
|
|
453
|
+
declare class Hyphen extends Hookified {
|
|
454
|
+
private readonly _netInfo;
|
|
455
|
+
private readonly _toggle;
|
|
456
|
+
private readonly _link;
|
|
457
|
+
private _publicApiKey?;
|
|
458
|
+
private _apiKey?;
|
|
459
|
+
constructor(options?: HyphenOptions);
|
|
460
|
+
/**
|
|
461
|
+
* Get the NetInfo service instance.
|
|
462
|
+
* @returns {NetInfo} The NetInfo service instance.
|
|
463
|
+
*/
|
|
464
|
+
get netInfo(): NetInfo;
|
|
465
|
+
/**
|
|
466
|
+
* Get the Toggle service instance.
|
|
467
|
+
* @returns {Toggle} The Toggle service instance.
|
|
468
|
+
*/
|
|
469
|
+
get toggle(): Toggle;
|
|
470
|
+
/**
|
|
471
|
+
* Get the Link service instance.
|
|
472
|
+
* @returns {Link} The Link service instance.
|
|
473
|
+
*/
|
|
474
|
+
get link(): Link;
|
|
475
|
+
/**
|
|
476
|
+
* Get the public API key for the Hyphen service.
|
|
477
|
+
* This is used for public endpoints that do not require authentication.
|
|
478
|
+
* @returns {string | undefined} The public API key.
|
|
479
|
+
*/
|
|
480
|
+
get publicApiKey(): string | undefined;
|
|
481
|
+
/**
|
|
482
|
+
* Set the public API key for the Hyphen service. If set, this will also update the underlying services.
|
|
483
|
+
* This is used for public endpoints that do not require authentication such as the Toggle service.
|
|
484
|
+
* @param {string | undefined} value - The public API key to set.
|
|
485
|
+
*/
|
|
486
|
+
set publicApiKey(value: string | undefined);
|
|
487
|
+
/**
|
|
488
|
+
* Get the API key for the Hyphen service.
|
|
489
|
+
* This is used for authenticated endpoints that require an API key such as the NetInfo and Link services.
|
|
490
|
+
* @returns {string | undefined} The API key.
|
|
491
|
+
*/
|
|
492
|
+
get apiKey(): string | undefined;
|
|
493
|
+
/**
|
|
494
|
+
* Set the API key for the Hyphen service. If set, this will also update the underlying services.
|
|
495
|
+
* This is used for authenticated endpoints that require an API key such as the NetInfo and Link services.
|
|
496
|
+
* @param {string | undefined} value - The API key to set.
|
|
497
|
+
*/
|
|
498
|
+
set apiKey(value: string | undefined);
|
|
499
|
+
/**
|
|
500
|
+
* Get whether to throw errors or not.
|
|
501
|
+
* If set to true, errors will be thrown instead of logged.
|
|
502
|
+
* @returns {boolean} Whether to throw errors or not.
|
|
503
|
+
*/
|
|
504
|
+
get throwErrors(): boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Set whether to throw errors or not. If set to true, errors will be thrown instead of logged.
|
|
507
|
+
* This will update the underlying services as well.
|
|
508
|
+
* @param {boolean} value - Whether to throw errors or not.
|
|
509
|
+
*/
|
|
510
|
+
set throwErrors(value: boolean);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export { Hyphen, type HyphenOptions, Toggle, type ToggleCachingOptions, type ToggleContext, type ToggleGetOptions, ToggleHooks, type ToggleOptions, loadEnv };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import { Hookified } from 'hookified';
|
|
1
|
+
import { Hookified, HookifiedOptions } from 'hookified';
|
|
2
2
|
import { EvaluationContext, Client } from '@openfeature/server-sdk';
|
|
3
|
+
import * as axios from 'axios';
|
|
4
|
+
import { AxiosRequestConfig } from 'axios';
|
|
5
|
+
import { Cacheable } from 'cacheable';
|
|
6
|
+
import pino from 'pino';
|
|
3
7
|
|
|
4
8
|
type ToggleContext = EvaluationContext;
|
|
5
9
|
declare enum ToggleHooks {
|
|
@@ -218,4 +222,292 @@ type LoadEnvOptions = {
|
|
|
218
222
|
*/
|
|
219
223
|
declare function loadEnv(options?: LoadEnvOptions): void;
|
|
220
224
|
|
|
221
|
-
|
|
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 LinkOptions = {
|
|
349
|
+
/**
|
|
350
|
+
* The URIs to access the link service.
|
|
351
|
+
* @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
|
|
352
|
+
*/
|
|
353
|
+
uris?: string[];
|
|
354
|
+
/**
|
|
355
|
+
* The organization ID to use for the link service.
|
|
356
|
+
* @requires organizationId
|
|
357
|
+
*/
|
|
358
|
+
organizationId?: string;
|
|
359
|
+
/**
|
|
360
|
+
* The API key to use for the link service. This should be provided as the service requires authentication.
|
|
361
|
+
*/
|
|
362
|
+
apiKey?: string;
|
|
363
|
+
} & BaseServiceOptions;
|
|
364
|
+
declare class Link extends BaseService {
|
|
365
|
+
private _uris;
|
|
366
|
+
private _organizationId?;
|
|
367
|
+
private _apiKey?;
|
|
368
|
+
constructor(options?: LinkOptions);
|
|
369
|
+
/**
|
|
370
|
+
* Get the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
371
|
+
* @returns {string[]} The URIs for the link service.
|
|
372
|
+
*/
|
|
373
|
+
get uris(): string[];
|
|
374
|
+
/**
|
|
375
|
+
* Set the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
|
|
376
|
+
* @param {string[]} uris - The URIs to set.
|
|
377
|
+
*/
|
|
378
|
+
set uris(uris: string[]);
|
|
379
|
+
/**
|
|
380
|
+
* Get the organization ID for the link service. This is required to access the link service.
|
|
381
|
+
* @returns {string | undefined} The organization ID.
|
|
382
|
+
*/
|
|
383
|
+
get organizationId(): string | undefined;
|
|
384
|
+
/**
|
|
385
|
+
* Set the organization ID for the link service. This is required to access the link service.
|
|
386
|
+
* @param {string | undefined} organizationId - The organization ID to set.
|
|
387
|
+
*/
|
|
388
|
+
set organizationId(organizationId: string | undefined);
|
|
389
|
+
/**
|
|
390
|
+
* Get the API key for the link service. This is required to access the link service.
|
|
391
|
+
* @returns {string | undefined} The API key.
|
|
392
|
+
*/
|
|
393
|
+
get apiKey(): string | undefined;
|
|
394
|
+
/**
|
|
395
|
+
* Set the API key for the link service. This is required to access the link service.
|
|
396
|
+
* @param {string | undefined} apiKey - The API key to set.
|
|
397
|
+
*/
|
|
398
|
+
set apiKey(apiKey: string | undefined);
|
|
399
|
+
/**
|
|
400
|
+
* Set the API key for the link service. If the API key starts with 'public_', an error is thrown.
|
|
401
|
+
* This is to ensure that the API key is not a public key, which should not be used for authenticated requests.
|
|
402
|
+
* @param {string} apiKey
|
|
403
|
+
*/
|
|
404
|
+
setApiKey(apiKey: string | undefined): void;
|
|
405
|
+
createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
|
|
406
|
+
/**
|
|
407
|
+
* Delete a short code.
|
|
408
|
+
* @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
|
|
409
|
+
* @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
|
|
410
|
+
*/
|
|
411
|
+
deleteShortCode(code: string): Promise<boolean>;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
type HyphenOptions = {
|
|
415
|
+
/**
|
|
416
|
+
* The public API key to use for the Hyphen service.
|
|
417
|
+
* This is used for public endpoints that do not require authentication.
|
|
418
|
+
*/
|
|
419
|
+
publicApiKey?: string;
|
|
420
|
+
/**
|
|
421
|
+
* The API key to use for the Hyphen service.
|
|
422
|
+
* This is used for authenticated endpoints that require an API key.
|
|
423
|
+
*/
|
|
424
|
+
apiKey?: string;
|
|
425
|
+
/**
|
|
426
|
+
* Whether to throw errors or not.
|
|
427
|
+
* If set to true, errors will be thrown instead of logged.
|
|
428
|
+
* @default false
|
|
429
|
+
*/
|
|
430
|
+
throwErrors?: boolean;
|
|
431
|
+
/**
|
|
432
|
+
* Options for the Toggle service.
|
|
433
|
+
* Excludes publicApiKey and throwErrors from ToggleOptions.
|
|
434
|
+
* @see ToggleOptions
|
|
435
|
+
* @default {Toggle}
|
|
436
|
+
*/
|
|
437
|
+
toggle?: Omit<ToggleOptions, 'publicApiKey' | 'throwErrors'>;
|
|
438
|
+
/**
|
|
439
|
+
* Options for the NetInfo service.
|
|
440
|
+
* Excludes apiKey and throwErrors from NetInfoOptions.
|
|
441
|
+
* @see NetInfoOptions
|
|
442
|
+
* @default {NetInfo}
|
|
443
|
+
*/
|
|
444
|
+
netInfo?: Omit<NetInfoOptions, 'apiKey' | 'throwErrors'>;
|
|
445
|
+
/**
|
|
446
|
+
* Options for the Link service.
|
|
447
|
+
* Excludes apiKey and throwErrors from LinkOptions.
|
|
448
|
+
* @see LinkOptions
|
|
449
|
+
* @default {Link}
|
|
450
|
+
*/
|
|
451
|
+
link?: Omit<LinkOptions, 'apiKey' | 'throwErrors'>;
|
|
452
|
+
} & HookifiedOptions;
|
|
453
|
+
declare class Hyphen extends Hookified {
|
|
454
|
+
private readonly _netInfo;
|
|
455
|
+
private readonly _toggle;
|
|
456
|
+
private readonly _link;
|
|
457
|
+
private _publicApiKey?;
|
|
458
|
+
private _apiKey?;
|
|
459
|
+
constructor(options?: HyphenOptions);
|
|
460
|
+
/**
|
|
461
|
+
* Get the NetInfo service instance.
|
|
462
|
+
* @returns {NetInfo} The NetInfo service instance.
|
|
463
|
+
*/
|
|
464
|
+
get netInfo(): NetInfo;
|
|
465
|
+
/**
|
|
466
|
+
* Get the Toggle service instance.
|
|
467
|
+
* @returns {Toggle} The Toggle service instance.
|
|
468
|
+
*/
|
|
469
|
+
get toggle(): Toggle;
|
|
470
|
+
/**
|
|
471
|
+
* Get the Link service instance.
|
|
472
|
+
* @returns {Link} The Link service instance.
|
|
473
|
+
*/
|
|
474
|
+
get link(): Link;
|
|
475
|
+
/**
|
|
476
|
+
* Get the public API key for the Hyphen service.
|
|
477
|
+
* This is used for public endpoints that do not require authentication.
|
|
478
|
+
* @returns {string | undefined} The public API key.
|
|
479
|
+
*/
|
|
480
|
+
get publicApiKey(): string | undefined;
|
|
481
|
+
/**
|
|
482
|
+
* Set the public API key for the Hyphen service. If set, this will also update the underlying services.
|
|
483
|
+
* This is used for public endpoints that do not require authentication such as the Toggle service.
|
|
484
|
+
* @param {string | undefined} value - The public API key to set.
|
|
485
|
+
*/
|
|
486
|
+
set publicApiKey(value: string | undefined);
|
|
487
|
+
/**
|
|
488
|
+
* Get the API key for the Hyphen service.
|
|
489
|
+
* This is used for authenticated endpoints that require an API key such as the NetInfo and Link services.
|
|
490
|
+
* @returns {string | undefined} The API key.
|
|
491
|
+
*/
|
|
492
|
+
get apiKey(): string | undefined;
|
|
493
|
+
/**
|
|
494
|
+
* Set the API key for the Hyphen service. If set, this will also update the underlying services.
|
|
495
|
+
* This is used for authenticated endpoints that require an API key such as the NetInfo and Link services.
|
|
496
|
+
* @param {string | undefined} value - The API key to set.
|
|
497
|
+
*/
|
|
498
|
+
set apiKey(value: string | undefined);
|
|
499
|
+
/**
|
|
500
|
+
* Get whether to throw errors or not.
|
|
501
|
+
* If set to true, errors will be thrown instead of logged.
|
|
502
|
+
* @returns {boolean} Whether to throw errors or not.
|
|
503
|
+
*/
|
|
504
|
+
get throwErrors(): boolean;
|
|
505
|
+
/**
|
|
506
|
+
* Set whether to throw errors or not. If set to true, errors will be thrown instead of logged.
|
|
507
|
+
* This will update the underlying services as well.
|
|
508
|
+
* @param {boolean} value - Whether to throw errors or not.
|
|
509
|
+
*/
|
|
510
|
+
set throwErrors(value: boolean);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
export { Hyphen, type HyphenOptions, Toggle, type ToggleCachingOptions, type ToggleContext, type ToggleGetOptions, ToggleHooks, type ToggleOptions, loadEnv };
|