@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/dist/index.d.cts CHANGED
@@ -1,252 +1,321 @@
1
- import { Hookified, HookifiedOptions } from 'hookified';
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 ToggleContext = EvaluationContext;
9
- declare enum ToggleHooks {
10
- beforeGetBoolean = "beforeGetBoolean",
11
- afterGetBoolean = "afterGetBoolean",
12
- beforeGetString = "beforeGetString",
13
- afterGetString = "afterGetString",
14
- beforeGetNumber = "beforeGetNumber",
15
- afterGetNumber = "afterGetNumber",
16
- beforeGetObject = "beforeGetObject",
17
- afterGetObject = "afterGetObject"
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
- type ToggleCachingOptions = {
20
- ttl?: number;
21
- generateCacheKeyFn?: (context?: ToggleContext) => string;
50
+
51
+ type ClickByDay = {
52
+ date: string;
53
+ total: number;
54
+ unique: number;
22
55
  };
23
- type ToggleOptions = {
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
- * Your application name. If this is not set it will look for the HYPHEN_APPLICATION_ID environment variable.
26
- * @type {string}
88
+ * The short code used for this link. If not provided, a random code will be generated.
89
+ * @default undefined
27
90
  */
28
- applicationId?: string;
91
+ code?: string;
29
92
  /**
30
- * Your Hyphen Public API key. If this is not set it will look for the HYPHEN_PUBLIC_API_KEY environment variable.
31
- * @type {string}
93
+ * The title of the link. This is used for display purposes.
94
+ * @default undefined
32
95
  */
33
- publicApiKey?: string;
96
+ title?: string;
34
97
  /**
35
- * Your environment name such as development, production. Default is what is set at NODE_ENV
36
- * @type {string}
37
- * @example production
98
+ * The tags associated with the link. This is used for categorization purposes.
99
+ * @default undefined
38
100
  */
39
- environment?: string;
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 context to use for evaluating feature flags
42
- * @type {ToggleContext}
119
+ * The long URL that the short code will redirect to.
120
+ * @default undefined
43
121
  */
44
- context?: ToggleContext;
122
+ long_url?: string;
45
123
  /**
46
- * Cache options to use for the request
47
- * @type {ToggleCachingOptions}
124
+ * The title of the link. This is used for display purposes.
125
+ * @default undefined
48
126
  */
49
- caching?: ToggleCachingOptions;
127
+ title?: string;
50
128
  /**
51
- * Throw errors in addition to emitting them
52
- * @type {boolean}
53
- * @default false
129
+ * The tags associated with the link. This is used for categorization purposes.
130
+ * @default undefined
54
131
  */
55
- throwErrors?: boolean;
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
- * Horizon URIs to use for talking to Toggle. You can use this to override
58
- * the default URIs for testin or if you are using a self-hosted version.
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
- uris?: string[];
63
- };
64
- type ToggleGetOptions = {
151
+ title?: string;
65
152
  /**
66
- * The context to use for evaluating feature flags
67
- * @type {ToggleContext}
153
+ * The background color of the QR code. This is a hex color code.
154
+ * @default '#ffffff'
68
155
  */
69
- context?: ToggleContext;
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
- declare class Toggle extends Hookified {
72
- private _applicationId;
73
- private _publicApiKey;
74
- private _environment;
75
- private _client;
76
- private _context;
77
- private _throwErrors;
78
- private _uris;
79
- private _caching;
80
- constructor(options?: ToggleOptions);
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
- * Get the application ID
83
- * @returns {string | undefined}
188
+ * The URIs to access the link service.
189
+ * @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
84
190
  */
85
- get applicationId(): string | undefined;
191
+ uris?: string[];
86
192
  /**
87
- * Set the application ID
88
- * @param {string | undefined} value
193
+ * The organization ID to use for the link service.
194
+ * @requires organizationId
89
195
  */
90
- set applicationId(value: string | undefined);
196
+ organizationId?: string;
91
197
  /**
92
- * Get the public API key
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
- get publicApiKey(): string | undefined;
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
- * Set the public API key
98
- * @param {string} value
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
- set publicApiKey(value: string | undefined);
211
+ get uris(): string[];
101
212
  /**
102
- * Get the environment
103
- * @returns {string}
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
- get environment(): string;
216
+ set uris(uris: string[]);
106
217
  /**
107
- * Set the environment
108
- * @param {string} value
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
- set environment(value: string);
221
+ get organizationId(): string | undefined;
111
222
  /**
112
- * Get the throwErrors. If true, errors will be thrown in addition to being emitted.
113
- * @returns {boolean}
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
- get throwErrors(): boolean;
226
+ set organizationId(organizationId: string | undefined);
116
227
  /**
117
- * Set the throwErrors. If true, errors will be thrown in addition to being emitted.
118
- * @param {boolean} value
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
- set throwErrors(value: boolean);
231
+ get apiKey(): string | undefined;
121
232
  /**
122
- * Get the current context. This is the default context used. You can override this at the get function level.
123
- * @returns {ToggleContext}
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
- get context(): ToggleContext | undefined;
236
+ set apiKey(apiKey: string | undefined);
126
237
  /**
127
- * Set the context. This is the default context used. You can override this at the get function level.
128
- * @param {ToggleContext} value
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
- set context(value: ToggleContext | undefined);
242
+ setApiKey(apiKey: string | undefined): void;
131
243
  /**
132
- * Get the URIs. This is used to override the default URIs for testing or if you are using a self-hosted version.
133
- * @returns {Array<string>}
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
- get uris(): string[] | undefined;
249
+ getUri(organizationId: string, prefix1?: string, prefix2?: string, prefix3?: string): string;
136
250
  /**
137
- * Set the URIs. This is used to override the default URIs for testing or if you are using a self-hosted version.
138
- * @param {Array<string>} value
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
- set uris(value: string[] | undefined);
257
+ createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
141
258
  /**
142
- * Get the caching options.
143
- * @returns {ToggleCachingOptions | undefined}
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
- get caching(): ToggleCachingOptions | undefined;
263
+ getShortCode(code: string): Promise<GetShortCodeResponse>;
146
264
  /**
147
- * Set the caching options.
148
- * @param {ToggleCachingOptions | undefined} value
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
- set caching(value: ToggleCachingOptions | undefined);
272
+ getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
151
273
  /**
152
- * 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
153
- * does set it will also set the client to undefined to force a new one to be created. If it does not,
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
- setPublicApiKey(key: string): void;
277
+ getTags(): Promise<string[]>;
159
278
  /**
160
- * Set the context. This is the default context used. You can override this at the get function level.
161
- * @param {ToggleContext} context
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
- setContext(context: ToggleContext): void;
283
+ getCodeStats(code: string, startDate: Date, endDate: Date): Promise<GetCodeStatsResponse>;
164
284
  /**
165
- * Helper function to get the client. This will create a new client if one does not exist. It will also set the
166
- * application ID, environment, and URIs if they are not set. This is used by the get function to get the client.
167
- * This is normally only used internally.
168
- * @returns {Promise<Client>}
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
- getClient(): Promise<Client>;
290
+ updateShortCode(code: string, options: UpdateShortCodeOptions): Promise<UpdateShortCodeResponse>;
171
291
  /**
172
- * This is the main function to get a feature flag value. It will check the type of the default value and call the
173
- * appropriate function. It will also set the context if it is not set.
174
- * @param {string} key - The key of the feature flag
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
- get<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
296
+ deleteShortCode(code: string): Promise<boolean>;
180
297
  /**
181
- * Get a boolean value from the feature flag. This will check the type of the default value and call the
182
- * appropriate function. It will also set the context if it is not set.
183
- * @param {string} key - The key of the feature flag
184
- * @param {boolean} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
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
- getBoolean(key: string, defaultValue: boolean, options?: ToggleGetOptions): Promise<boolean>;
303
+ createQrCode(code: string, options?: CreateQrCodeOptions): Promise<CreateQrCodeResponse>;
189
304
  /**
190
- * Get a string value from the feature flag.
191
- * @param {string} key - The key of the feature flag
192
- * @param {string} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
193
- * @param {ToggleRequestOptions} options - The options to use for the request. This can be used to override the context.
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
- getString(key: string, defaultValue: string, options?: ToggleGetOptions): Promise<string>;
197
- getNumber(key: string, defaultValue: number, options?: ToggleGetOptions): Promise<number>;
310
+ getQrCode(code: string, qr: string): Promise<CreateQrCodeResponse>;
311
+ getQrCodes(code: string, pageNumber?: number, pageSize?: number): Promise<GetQrCodesResponse>;
198
312
  /**
199
- * Get an object value from the feature flag. This will check the type of the default value and call the
200
- * appropriate function. It will also set the context if it is not set.
201
- * @param {string} key - The key of the feature flag
202
- * @param {T} defaultValue - The default value to return if the feature flag is not set or does not evaluate.
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
- getObject<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
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 ClickByDay = {
321
- date: string;
322
- total: number;
323
- unique: number;
324
- };
325
- type Clicks = {
326
- total: number;
327
- unique: number;
328
- byDay: ClickByDay[];
329
- };
330
- type Referral = {
331
- url: string;
332
- total: number;
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 UpdateShortCodeResponse = CreateShortCodeResponse;
386
- type UpdateShortCodeOptions = {
404
+ type ToggleOptions = {
387
405
  /**
388
- * The long URL that the short code will redirect to.
389
- * @default undefined
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
- long_url?: string;
409
+ applicationId?: string;
392
410
  /**
393
- * The title of the link. This is used for display purposes.
394
- * @default undefined
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
- title?: string;
414
+ publicApiKey?: string;
397
415
  /**
398
- * The tags associated with the link. This is used for categorization purposes.
399
- * @default undefined
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
- tags?: string[];
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 title of the QR code. This is used for display purposes.
418
- * @default undefined
422
+ * The context to use for evaluating feature flags
423
+ * @type {ToggleContext}
419
424
  */
420
- title?: string;
425
+ context?: ToggleContext;
421
426
  /**
422
- * The background color of the QR code. This is a hex color code.
423
- * @default '#ffffff'
427
+ * Cache options to use for the request
428
+ * @type {ToggleCachingOptions}
424
429
  */
425
- backgroundColor?: string;
430
+ caching?: ToggleCachingOptions;
426
431
  /**
427
- * The color of the QR code. This is a hex color code.
428
- * @default '#000000'
432
+ * Throw errors in addition to emitting them
433
+ * @type {boolean}
434
+ * @default false
429
435
  */
430
- color?: string;
436
+ throwErrors?: boolean;
431
437
  /**
432
- * The size of the QR code. This can be 'small', 'medium', or 'large'.
433
- * @default QrSize.MEDIUM
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
- size?: QrSize;
443
+ uris?: string[];
444
+ };
445
+ type ToggleGetOptions = {
436
446
  /**
437
- * The logo to include in the QR code. This should be a base64 encoded string.
438
- * @default undefined
447
+ * The context to use for evaluating feature flags
448
+ * @type {ToggleContext}
439
449
  */
440
- logo?: string;
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
- type LinkOptions = {
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
- * The URIs to access the link service.
458
- * @default ["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]
463
+ * Get the application ID
464
+ * @returns {string | undefined}
459
465
  */
460
- uris?: string[];
466
+ get applicationId(): string | undefined;
461
467
  /**
462
- * The organization ID to use for the link service.
463
- * @requires organizationId
468
+ * Set the application ID
469
+ * @param {string | undefined} value
464
470
  */
465
- organizationId?: string;
471
+ set applicationId(value: string | undefined);
466
472
  /**
467
- * The API key to use for the link service. This should be provided as the service requires authentication.
473
+ * Get the public API key
474
+ * @returns {string}
468
475
  */
469
- apiKey?: string;
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
- * Get the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
478
- * @returns {string[]} The URIs for the link service.
478
+ * Set the public API key
479
+ * @param {string} value
479
480
  */
480
- get uris(): string[];
481
+ set publicApiKey(value: string | undefined);
481
482
  /**
482
- * Set the URIs for the link service. The default is `["https://api.hyphen.ai/api/organizations/{organizationId}/link/codes/"]`.
483
- * @param {string[]} uris - The URIs to set.
483
+ * Get the environment
484
+ * @returns {string}
484
485
  */
485
- set uris(uris: string[]);
486
+ get environment(): string;
486
487
  /**
487
- * Get the organization ID for the link service. This is required to access the link service.
488
- * @returns {string | undefined} The organization ID.
488
+ * Set the environment
489
+ * @param {string} value
489
490
  */
490
- get organizationId(): string | undefined;
491
+ set environment(value: string);
491
492
  /**
492
- * Set the organization ID for the link service. This is required to access the link service.
493
- * @param {string | undefined} organizationId - The organization ID to set.
493
+ * Get the throwErrors. If true, errors will be thrown in addition to being emitted.
494
+ * @returns {boolean}
494
495
  */
495
- set organizationId(organizationId: string | undefined);
496
+ get throwErrors(): boolean;
496
497
  /**
497
- * Get the API key for the link service. This is required to access the link service.
498
- * @returns {string | undefined} The API key.
498
+ * Set the throwErrors. If true, errors will be thrown in addition to being emitted.
499
+ * @param {boolean} value
499
500
  */
500
- get apiKey(): string | undefined;
501
+ set throwErrors(value: boolean);
501
502
  /**
502
- * Set the API key for the link service. This is required to access the link service.
503
- * @param {string | undefined} apiKey - The API key to set.
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
- set apiKey(apiKey: string | undefined);
506
+ get context(): ToggleContext | undefined;
506
507
  /**
507
- * Set the API key for the link service. If the API key starts with 'public_', an error is thrown.
508
- * This is to ensure that the API key is not a public key, which should not be used for authenticated requests.
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
- setApiKey(apiKey: string | undefined): void;
511
+ set context(value: ToggleContext | undefined);
512
512
  /**
513
- * Get the URI for a specific organization and code. This is used internally to construct the URI for the link service.
514
- * @param {string} organizationId The ID of the organization.
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
- getUri(organizationId: string, prefix1?: string, prefix2?: string, prefix3?: string): string;
516
+ get uris(): string[] | undefined;
519
517
  /**
520
- * Create a short code for a long URL.
521
- * @param {string} longUrl The long URL to shorten.
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
- createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
521
+ set uris(value: string[] | undefined);
527
522
  /**
528
- * Get a short code by its code.
529
- * @param {string} code The short code to retrieve. Example: 'code_686bed403c3991bd676bba4d'
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
- getShortCode(code: string): Promise<GetShortCodeResponse>;
526
+ get caching(): ToggleCachingOptions | undefined;
533
527
  /**
534
- * Get all short codes for the organization.
535
- * @param {string} titleSearch Optional search term to filter short codes by title.
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
- getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
531
+ set caching(value: ToggleCachingOptions | undefined);
542
532
  /**
543
- * Get all tags associated with the organization's short codes.
544
- * @returns {Promise<string[]>} A promise that resolves to an array of tags.
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
- getTags(): Promise<string[]>;
539
+ setPublicApiKey(key: string): void;
547
540
  /**
548
- * Get statistics for a specific short code.
549
- * @param code The short code to retrieve statistics for.
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
- getCodeStats(code: string, startDate: Date, endDate: Date): Promise<GetCodeStatsResponse>;
544
+ setContext(context: ToggleContext): void;
553
545
  /**
554
- * Update a short code.
555
- * @param {string} code The short code to update. Example: 'code_686bed403c3991bd676bba4d'
556
- * @param {UpdateShortCodeOptions} options The options to update the short code with.
557
- * @returns {Promise<UpdateShortCodeResponse>} A promise that resolves to the updated short code details.
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
- updateShortCode(code: string, options: UpdateShortCodeOptions): Promise<UpdateShortCodeResponse>;
551
+ getClient(): Promise<Client>;
560
552
  /**
561
- * Delete a short code.
562
- * @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
563
- * @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
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
- deleteShortCode(code: string): Promise<boolean>;
560
+ get<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
566
561
  /**
567
- * Create a QR code for a specific short code.
568
- * @param {string} code The short code to create a QR code for.
569
- * @param {CreateQrCodeOptions} options The options for creating the QR code.
570
- * @returns {Promise<CreateQrCodeResponse>} A promise that resolves to the created QR code details.
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
- createQrCode(code: string, options?: CreateQrCodeOptions): Promise<CreateQrCodeResponse>;
569
+ getBoolean(key: string, defaultValue: boolean, options?: ToggleGetOptions): Promise<boolean>;
573
570
  /**
574
- * Get a QR code by its ID.
575
- * @param code The short code associated with the QR code.
576
- * @param qr The ID of the QR code to retrieve.
577
- * @returns The details of the requested QR code.
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
- getQrCode(code: string, qr: string): Promise<CreateQrCodeResponse>;
580
- getQrCodes(code: string, pageNumber?: number, pageSize?: number): Promise<GetQrCodesResponse>;
577
+ getString(key: string, defaultValue: string, options?: ToggleGetOptions): Promise<string>;
578
+ getNumber(key: string, defaultValue: number, options?: ToggleGetOptions): Promise<number>;
581
579
  /**
582
- * Delete a QR code by its ID.
583
- * @param {string} code The short code associated with the QR code.
584
- * @param {string} qr The ID of the QR code to delete.
585
- * @returns {Promise<boolean>} A promise that resolves to true if the QR code was deleted successfully, or false if it was not.
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
- deleteQrCode(code: string, qr: string): Promise<boolean>;
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, 'publicApiKey' | 'throwErrors'>;
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, 'apiKey' | 'throwErrors'>;
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, 'apiKey' | 'throwErrors'>;
627
+ link?: Omit<LinkOptions, "apiKey" | "throwErrors">;
628
628
  } & HookifiedOptions;
629
629
  declare class Hyphen extends Hookified {
630
630
  private readonly _netInfo;