@hyphen/sdk 1.10.0 → 1.12.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/dist/index.d.cts CHANGED
@@ -206,7 +206,7 @@ declare class Toggle extends Hookified {
206
206
  getObject<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
207
207
  }
208
208
 
209
- type LoadEnvOptions = {
209
+ type EnvOptions = {
210
210
  path?: string;
211
211
  environment?: string;
212
212
  local?: boolean;
@@ -214,13 +214,15 @@ type LoadEnvOptions = {
214
214
  /**
215
215
  * @description Helper function to load your environment variables based on your default .env file
216
216
  * and the current environment.
217
- * @param {LoadEnvOptions} [options] - Options to customize the loading of environment variables.
217
+ * @param {EnvOptions} [options] - Options to customize the loading of environment variables.
218
218
  * @returns {void}
219
219
  * @example
220
- * import { loadEnv } from '@hyphen/sdk';
221
- * loadEnv();
220
+ * import { env } from '@hyphen/sdk';
221
+ * env();
222
222
  */
223
- declare function loadEnv(options?: LoadEnvOptions): void;
223
+ declare function env(options?: EnvOptions): void;
224
+ declare const loadEnv: typeof env;
225
+ type LoadEnvOptions = EnvOptions;
224
226
 
225
227
  type BaseServiceOptions = {
226
228
  throwErrors?: boolean;
@@ -315,6 +317,41 @@ declare class NetInfo extends BaseService {
315
317
  getIpInfos(ips: string[]): Promise<Array<ipInfo | ipInfoError>>;
316
318
  }
317
319
 
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
+
318
355
  type CreateShortCodeOptions = {
319
356
  /**
320
357
  * The short code used for this link. If not provided, a random code will be generated.
@@ -345,6 +382,76 @@ type CreateShortCodeResponse = {
345
382
  name: string;
346
383
  };
347
384
  };
385
+ type UpdateShortCodeResponse = CreateShortCodeResponse;
386
+ type UpdateShortCodeOptions = {
387
+ /**
388
+ * The long URL that the short code will redirect to.
389
+ * @default undefined
390
+ */
391
+ long_url?: string;
392
+ /**
393
+ * The title of the link. This is used for display purposes.
394
+ * @default undefined
395
+ */
396
+ title?: string;
397
+ /**
398
+ * The tags associated with the link. This is used for categorization purposes.
399
+ * @default undefined
400
+ */
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 = {
416
+ /**
417
+ * The title of the QR code. This is used for display purposes.
418
+ * @default undefined
419
+ */
420
+ title?: string;
421
+ /**
422
+ * The background color of the QR code. This is a hex color code.
423
+ * @default '#ffffff'
424
+ */
425
+ backgroundColor?: string;
426
+ /**
427
+ * The color of the QR code. This is a hex color code.
428
+ * @default '#000000'
429
+ */
430
+ color?: string;
431
+ /**
432
+ * The size of the QR code. This can be 'small', 'medium', or 'large'.
433
+ * @default QrSize.MEDIUM
434
+ */
435
+ size?: QrSize;
436
+ /**
437
+ * The logo to include in the QR code. This should be a base64 encoded string.
438
+ * @default undefined
439
+ */
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[];
454
+ };
348
455
  type LinkOptions = {
349
456
  /**
350
457
  * The URIs to access the link service.
@@ -402,13 +509,82 @@ declare class Link extends BaseService {
402
509
  * @param {string} apiKey
403
510
  */
404
511
  setApiKey(apiKey: string | undefined): void;
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.
517
+ */
518
+ getUri(organizationId: string, prefix1?: string, prefix2?: string, prefix3?: string): string;
519
+ /**
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.
525
+ */
405
526
  createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
527
+ /**
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.
531
+ */
532
+ getShortCode(code: string): Promise<GetShortCodeResponse>;
533
+ /**
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.
540
+ */
541
+ getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
542
+ /**
543
+ * Get all tags associated with the organization's short codes.
544
+ * @returns {Promise<string[]>} A promise that resolves to an array of tags.
545
+ */
546
+ getTags(): Promise<string[]>;
547
+ /**
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.
551
+ */
552
+ getCodeStats(code: string, startDate: Date, endDate: Date): Promise<GetCodeStatsResponse>;
553
+ /**
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.
558
+ */
559
+ updateShortCode(code: string, options: UpdateShortCodeOptions): Promise<UpdateShortCodeResponse>;
406
560
  /**
407
561
  * Delete a short code.
408
562
  * @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
409
563
  * @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
410
564
  */
411
565
  deleteShortCode(code: string): Promise<boolean>;
566
+ /**
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.
571
+ */
572
+ createQrCode(code: string, options?: CreateQrCodeOptions): Promise<CreateQrCodeResponse>;
573
+ /**
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.
578
+ */
579
+ getQrCode(code: string, qr: string): Promise<CreateQrCodeResponse>;
580
+ getQrCodes(code: string, pageNumber?: number, pageSize?: number): Promise<GetQrCodesResponse>;
581
+ /**
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.
586
+ */
587
+ deleteQrCode(code: string, qr: string): Promise<boolean>;
412
588
  }
413
589
 
414
590
  type HyphenOptions = {
@@ -510,4 +686,4 @@ declare class Hyphen extends Hookified {
510
686
  set throwErrors(value: boolean);
511
687
  }
512
688
 
513
- 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 };
package/dist/index.d.ts CHANGED
@@ -206,7 +206,7 @@ declare class Toggle extends Hookified {
206
206
  getObject<T>(key: string, defaultValue: T, options?: ToggleGetOptions): Promise<T>;
207
207
  }
208
208
 
209
- type LoadEnvOptions = {
209
+ type EnvOptions = {
210
210
  path?: string;
211
211
  environment?: string;
212
212
  local?: boolean;
@@ -214,13 +214,15 @@ type LoadEnvOptions = {
214
214
  /**
215
215
  * @description Helper function to load your environment variables based on your default .env file
216
216
  * and the current environment.
217
- * @param {LoadEnvOptions} [options] - Options to customize the loading of environment variables.
217
+ * @param {EnvOptions} [options] - Options to customize the loading of environment variables.
218
218
  * @returns {void}
219
219
  * @example
220
- * import { loadEnv } from '@hyphen/sdk';
221
- * loadEnv();
220
+ * import { env } from '@hyphen/sdk';
221
+ * env();
222
222
  */
223
- declare function loadEnv(options?: LoadEnvOptions): void;
223
+ declare function env(options?: EnvOptions): void;
224
+ declare const loadEnv: typeof env;
225
+ type LoadEnvOptions = EnvOptions;
224
226
 
225
227
  type BaseServiceOptions = {
226
228
  throwErrors?: boolean;
@@ -315,6 +317,41 @@ declare class NetInfo extends BaseService {
315
317
  getIpInfos(ips: string[]): Promise<Array<ipInfo | ipInfoError>>;
316
318
  }
317
319
 
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
+
318
355
  type CreateShortCodeOptions = {
319
356
  /**
320
357
  * The short code used for this link. If not provided, a random code will be generated.
@@ -345,6 +382,76 @@ type CreateShortCodeResponse = {
345
382
  name: string;
346
383
  };
347
384
  };
385
+ type UpdateShortCodeResponse = CreateShortCodeResponse;
386
+ type UpdateShortCodeOptions = {
387
+ /**
388
+ * The long URL that the short code will redirect to.
389
+ * @default undefined
390
+ */
391
+ long_url?: string;
392
+ /**
393
+ * The title of the link. This is used for display purposes.
394
+ * @default undefined
395
+ */
396
+ title?: string;
397
+ /**
398
+ * The tags associated with the link. This is used for categorization purposes.
399
+ * @default undefined
400
+ */
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 = {
416
+ /**
417
+ * The title of the QR code. This is used for display purposes.
418
+ * @default undefined
419
+ */
420
+ title?: string;
421
+ /**
422
+ * The background color of the QR code. This is a hex color code.
423
+ * @default '#ffffff'
424
+ */
425
+ backgroundColor?: string;
426
+ /**
427
+ * The color of the QR code. This is a hex color code.
428
+ * @default '#000000'
429
+ */
430
+ color?: string;
431
+ /**
432
+ * The size of the QR code. This can be 'small', 'medium', or 'large'.
433
+ * @default QrSize.MEDIUM
434
+ */
435
+ size?: QrSize;
436
+ /**
437
+ * The logo to include in the QR code. This should be a base64 encoded string.
438
+ * @default undefined
439
+ */
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[];
454
+ };
348
455
  type LinkOptions = {
349
456
  /**
350
457
  * The URIs to access the link service.
@@ -402,13 +509,82 @@ declare class Link extends BaseService {
402
509
  * @param {string} apiKey
403
510
  */
404
511
  setApiKey(apiKey: string | undefined): void;
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.
517
+ */
518
+ getUri(organizationId: string, prefix1?: string, prefix2?: string, prefix3?: string): string;
519
+ /**
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.
525
+ */
405
526
  createShortCode(longUrl: string, domain: string, options?: CreateShortCodeOptions): Promise<CreateShortCodeResponse>;
527
+ /**
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.
531
+ */
532
+ getShortCode(code: string): Promise<GetShortCodeResponse>;
533
+ /**
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.
540
+ */
541
+ getShortCodes(titleSearch: string, tags?: string[], pageNumber?: number, pageSize?: number): Promise<GetShortCodesResponse>;
542
+ /**
543
+ * Get all tags associated with the organization's short codes.
544
+ * @returns {Promise<string[]>} A promise that resolves to an array of tags.
545
+ */
546
+ getTags(): Promise<string[]>;
547
+ /**
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.
551
+ */
552
+ getCodeStats(code: string, startDate: Date, endDate: Date): Promise<GetCodeStatsResponse>;
553
+ /**
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.
558
+ */
559
+ updateShortCode(code: string, options: UpdateShortCodeOptions): Promise<UpdateShortCodeResponse>;
406
560
  /**
407
561
  * Delete a short code.
408
562
  * @param {string} code The short code to delete. Example: 'code_686bed403c3991bd676bba4d'
409
563
  * @returns {Promise<boolean>} A promise that resolves to true if the short code was deleted successfully, or false if it was not.
410
564
  */
411
565
  deleteShortCode(code: string): Promise<boolean>;
566
+ /**
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.
571
+ */
572
+ createQrCode(code: string, options?: CreateQrCodeOptions): Promise<CreateQrCodeResponse>;
573
+ /**
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.
578
+ */
579
+ getQrCode(code: string, qr: string): Promise<CreateQrCodeResponse>;
580
+ getQrCodes(code: string, pageNumber?: number, pageSize?: number): Promise<GetQrCodesResponse>;
581
+ /**
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.
586
+ */
587
+ deleteQrCode(code: string, qr: string): Promise<boolean>;
412
588
  }
413
589
 
414
590
  type HyphenOptions = {
@@ -510,4 +686,4 @@ declare class Hyphen extends Hookified {
510
686
  set throwErrors(value: boolean);
511
687
  }
512
688
 
513
- 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 };