saasco-sdk 0.1.12 → 0.1.13

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 CHANGED
@@ -35,8 +35,8 @@ export const saasco = new Saasco({ projectId: 'YOUR-PROJECT-ID' });
35
35
 
36
36
  ## Init Automatic Page View Tracking
37
37
 
38
- When you initial the lib Saasco will automatically start tracking all page views in your app. There is no other configuration. It will automatically track url changes, even for SPAs like NextJs and Vue.
39
- You can also [manually track pages](https://www.notion.so/Manual-Page-Tracking-in-SPAs-2442fc7586dc4208ae8f669eb7561b1a?pvs=21) by opting our of automatic page tracking. For most use cases you don't need to do this.
38
+ When you initiate the lib Saasco will automatically start tracking all page views in your app. There is no other configuration. It will automatically track url changes, even for SPAs like NextJs and Vue.
39
+ You can also [manually track pages](https://www.notion.so/Manual-Page-Tracking-in-SPAs-2442fc7586dc4208ae8f669eb7561b1a?pvs=21) by opting out of automatic page tracking. For most use cases you don't need to do this.
40
40
 
41
41
  ```ts
42
42
  // ./app/index
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.12";
437
+ var version = "0.1.13";
438
438
 
439
439
  const isBrowser = typeof window !== 'undefined';
440
440
  let userId = null;
@@ -555,9 +555,6 @@ class Saasco {
555
555
  this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
556
556
  }
557
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
- }
561
558
  if (this.isInitialized) {
562
559
  this.log('Saasco is already initialized. Please check your code to ensure that init() is not being called multiple times.');
563
560
  return;
@@ -691,13 +688,13 @@ class Saasco {
691
688
  body: JSON.stringify(data)
692
689
  });
693
690
  if (!response.ok) {
694
- throw new Error(response.status.toString());
691
+ const errorBody = yield response.json();
692
+ throw new Error(`${errorBody.message}: ${errorBody.errors ? `[${errorBody.errors.join(', ')}]` : ''}` || JSON.stringify(errorBody));
695
693
  }
696
694
  return response;
697
695
  } catch (error) {
698
- const errorMessage = 'Error with Saasco request: ' + error.message;
699
- console.error(errorMessage, path, data);
700
- return errorMessage;
696
+ this.error(`\nError Message: "${error.message}"`, `\nPath: "/${path}"`, `\nRequest Data: ${JSON.stringify(data, null, 2)}`);
697
+ return error.message;
701
698
  }
702
699
  });
703
700
  }
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.12";
433
+ var version = "0.1.13";
434
434
 
435
435
  const isBrowser = typeof window !== 'undefined';
436
436
  let userId = null;
@@ -551,9 +551,6 @@ class Saasco {
551
551
  this.config.enabled = this.config.enabled === undefined ? true : this.config.enabled;
552
552
  }
553
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
- }
557
554
  if (this.isInitialized) {
558
555
  this.log('Saasco is already initialized. Please check your code to ensure that init() is not being called multiple times.');
559
556
  return;
@@ -687,13 +684,13 @@ class Saasco {
687
684
  body: JSON.stringify(data)
688
685
  });
689
686
  if (!response.ok) {
690
- throw new Error(response.status.toString());
687
+ const errorBody = yield response.json();
688
+ throw new Error(`${errorBody.message}: ${errorBody.errors ? `[${errorBody.errors.join(', ')}]` : ''}` || JSON.stringify(errorBody));
691
689
  }
692
690
  return response;
693
691
  } catch (error) {
694
- const errorMessage = 'Error with Saasco request: ' + error.message;
695
- console.error(errorMessage, path, data);
696
- return errorMessage;
692
+ this.error(`\nError Message: "${error.message}"`, `\nPath: "/${path}"`, `\nRequest Data: ${JSON.stringify(data, null, 2)}`);
693
+ return error.message;
697
694
  }
698
695
  });
699
696
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "saasco-sdk",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
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
- }): void | Promise<string | Response | undefined>;
40
+ }): void | Promise<any>;
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(): void | Promise<string | Response | undefined>;
47
+ page(): void | Promise<any>;
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.