saasco-sdk 0.1.11 → 0.1.12

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/index.cjs.js CHANGED
@@ -434,7 +434,7 @@ const timezones = {
434
434
  'Asia/Calcutta': 'IN'
435
435
  };
436
436
 
437
- var version = "0.1.11";
437
+ var version = "0.1.12";
438
438
 
439
439
  const isBrowser = typeof window !== 'undefined';
440
440
  let userId = null;
@@ -547,10 +547,17 @@ class Saasco {
547
547
  this.config = config;
548
548
  this.lastPageViewHref = '';
549
549
  this.isInitialized = false;
550
+ if (!config.projectId) {
551
+ this.error("Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
552
+ return;
553
+ }
550
554
  // default enabled to true
551
555
  this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
552
556
  }
553
557
  init() {
558
+ if (!this.config.projectId) {
559
+ return this.error("Unable to initialize Saasco. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
560
+ }
554
561
  if (this.isInitialized) {
555
562
  this.log('Saasco is already initialized. Please check your code to ensure that init() is not being called multiple times.');
556
563
  return;
@@ -583,6 +590,9 @@ class Saasco {
583
590
  track(name,
584
591
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
585
592
  properties, context) {
593
+ if (!this.config.projectId) {
594
+ return this.error("Unable to track event. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
595
+ }
586
596
  // Prevent duplicate Page View tracking
587
597
  if (name === 'Page View') {
588
598
  if (!isBrowser) {
@@ -622,6 +632,9 @@ class Saasco {
622
632
  return this.track('Page View');
623
633
  }
624
634
  identify(distinctIdOrProperties, propertiesOrContext, contextOrNothing) {
635
+ if (!this.config.projectId) {
636
+ return this.error("Unable to identify user. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
637
+ }
625
638
  const hasId = typeof distinctIdOrProperties === 'string' || typeof distinctIdOrProperties === 'number' || distinctIdOrProperties === null;
626
639
  const distinctId = hasId ? distinctIdOrProperties === null || distinctIdOrProperties === void 0 ? void 0 : distinctIdOrProperties.toString() : `soft_${uuid.v4()}`;
627
640
  const properties = hasId ? propertiesOrContext : distinctIdOrProperties;
@@ -698,6 +711,15 @@ class Saasco {
698
711
  // Message highlighted for easy finding
699
712
  ...args]);
700
713
  }
714
+ /**
715
+ * @param args Arguments to be logged
716
+ */
717
+ error(...args) {
718
+ const message = '◍ Saasco Error';
719
+ console.error(...[`\x1b[41m\x1b[37m ${message} \x1b[0m`,
720
+ // Message highlighted for easy finding
721
+ ...args]);
722
+ }
701
723
  /**
702
724
  * If autoPageTracking is enabled, this will automatically track page views
703
725
  * It listens to url changes to track new pages every time the url changes
package/index.esm.js CHANGED
@@ -430,7 +430,7 @@ const timezones = {
430
430
  'Asia/Calcutta': 'IN'
431
431
  };
432
432
 
433
- var version = "0.1.11";
433
+ var version = "0.1.12";
434
434
 
435
435
  const isBrowser = typeof window !== 'undefined';
436
436
  let userId = null;
@@ -543,10 +543,17 @@ class Saasco {
543
543
  this.config = config;
544
544
  this.lastPageViewHref = '';
545
545
  this.isInitialized = false;
546
+ if (!config.projectId) {
547
+ this.error("Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
548
+ return;
549
+ }
546
550
  // default enabled to true
547
551
  this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
548
552
  }
549
553
  init() {
554
+ if (!this.config.projectId) {
555
+ return this.error("Unable to initialize Saasco. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
556
+ }
550
557
  if (this.isInitialized) {
551
558
  this.log('Saasco is already initialized. Please check your code to ensure that init() is not being called multiple times.');
552
559
  return;
@@ -579,6 +586,9 @@ class Saasco {
579
586
  track(name,
580
587
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
581
588
  properties, context) {
589
+ if (!this.config.projectId) {
590
+ return this.error("Unable to track event. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
591
+ }
582
592
  // Prevent duplicate Page View tracking
583
593
  if (name === 'Page View') {
584
594
  if (!isBrowser) {
@@ -618,6 +628,9 @@ class Saasco {
618
628
  return this.track('Page View');
619
629
  }
620
630
  identify(distinctIdOrProperties, propertiesOrContext, contextOrNothing) {
631
+ if (!this.config.projectId) {
632
+ return this.error("Unable to identify user. Project ID is required but has not been provided. If you are using an env variable make sure it's set correctly.");
633
+ }
621
634
  const hasId = typeof distinctIdOrProperties === 'string' || typeof distinctIdOrProperties === 'number' || distinctIdOrProperties === null;
622
635
  const distinctId = hasId ? distinctIdOrProperties === null || distinctIdOrProperties === void 0 ? void 0 : distinctIdOrProperties.toString() : `soft_${v4()}`;
623
636
  const properties = hasId ? propertiesOrContext : distinctIdOrProperties;
@@ -694,6 +707,15 @@ class Saasco {
694
707
  // Message highlighted for easy finding
695
708
  ...args]);
696
709
  }
710
+ /**
711
+ * @param args Arguments to be logged
712
+ */
713
+ error(...args) {
714
+ const message = '◍ Saasco Error';
715
+ console.error(...[`\x1b[41m\x1b[37m ${message} \x1b[0m`,
716
+ // Message highlighted for easy finding
717
+ ...args]);
718
+ }
697
719
  /**
698
720
  * If autoPageTracking is enabled, this will automatically track page views
699
721
  * It listens to url changes to track new pages every time the url changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasco-sdk",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "dependencies": {
5
5
  "tslib": "^2.3.0",
6
6
  "@lukeed/uuid": "^2.0.1",
@@ -37,14 +37,14 @@ export declare class Saasco {
37
37
  */
38
38
  track(name: string, properties?: Record<string, any>, context?: {
39
39
  active?: boolean;
40
- }): Promise<string | Response | undefined> | undefined;
40
+ }): void | Promise<string | Response | undefined>;
41
41
  /**
42
42
  * The page method lets you record page views on your website
43
43
  * This records the page title and path and names the event useing the reserved property "Page Viewed"
44
44
  *
45
45
  * Before implementing this make sure you have disabled the autoPageTracking in the config or you will get duplicate page views
46
46
  */
47
- page(): Promise<string | Response | undefined> | undefined;
47
+ page(): void | Promise<string | Response | undefined>;
48
48
  /**
49
49
  * The identify method lets you tie a user to their actions and record traits about them.
50
50
  * We recommend you call this when the user logs in and when any traits get updated.
@@ -71,6 +71,10 @@ export declare class Saasco {
71
71
  * @param args Arguments to be logged
72
72
  */
73
73
  private log;
74
+ /**
75
+ * @param args Arguments to be logged
76
+ */
77
+ private error;
74
78
  /**
75
79
  * If autoPageTracking is enabled, this will automatically track page views
76
80
  * It listens to url changes to track new pages every time the url changes