saasco-sdk 0.1.19 → 0.1.20

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
@@ -2,41 +2,11 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var tslib = require('tslib');
5
6
  var uuid = require('@lukeed/uuid');
6
7
  var zod = require('zod');
7
- var react = require('react');
8
8
 
9
- /******************************************************************************
10
- Copyright (c) Microsoft Corporation.
11
-
12
- Permission to use, copy, modify, and/or distribute this software for any
13
- purpose with or without fee is hereby granted.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
16
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
18
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
- PERFORMANCE OF THIS SOFTWARE.
22
- ***************************************************************************** */
23
-
24
- function __awaiter(thisArg, _arguments, P, generator) {
25
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
26
- return new (P || (P = Promise))(function (resolve, reject) {
27
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
28
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
29
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
30
- step((generator = generator.apply(thisArg, _arguments || [])).next());
31
- });
32
- }
33
-
34
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
35
- var e = new Error(message);
36
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
37
- };
38
-
39
- var version = "0.1.19";
9
+ var version = "0.1.20";
40
10
 
41
11
  const timezones = {
42
12
  'Asia/Barnaul': 'RU',
@@ -609,6 +579,8 @@ class Saasco {
609
579
  window.saasco = this;
610
580
  }
611
581
  this.log('Saasco initialized', this.config);
582
+ if (this.config.debug) this.log('Debug mode active. This will log all events to the console.');
583
+ if (!this.config.enabled) this.log('Analytics is disabled. No requests will be sent to the server.');
612
584
  this.initiAutoPageTracking();
613
585
  this.isInitialized = true;
614
586
  }
@@ -739,12 +711,14 @@ class Saasco {
739
711
  * @param data
740
712
  */
741
713
  doRequest(path, data) {
742
- return __awaiter(this, void 0, void 0, function* () {
714
+ return tslib.__awaiter(this, void 0, void 0, function* () {
743
715
  const base = this.config.proxy || 'https://www.saasco.com/api/';
744
716
  const url = `${base}${path}`;
745
- const logMessage = data.action === 'Page View' ? `Page View ${window.location.pathname}` // if its a page view, include pathname in console log
746
- : data.action || path;
747
- this.log(logMessage, data);
717
+ if (data.action === 'Page View') {
718
+ this.log('Page View', window.location.href, data);
719
+ } else {
720
+ this.log(data.action || path, data);
721
+ }
748
722
  // If analytics is disabled, don't send the request
749
723
  if (this.config.enabled === false) return {
750
724
  success: false,
@@ -781,18 +755,18 @@ class Saasco {
781
755
  log(...args) {
782
756
  if (!this.config.debug) return;
783
757
  const message = '◍ Saasco Debug';
784
- console.info(...[`\x1b[47m\x1b[30m ${message} \x1b[0m`,
758
+ console.info(
785
759
  // Message highlighted for easy finding
786
- ...args]);
760
+ `%c ${message}`, 'background: #eee; color: #000; padding: 2px 4px; border-radius: 2px;', ...args);
787
761
  }
788
762
  /**
789
763
  * @param args Arguments to be logged
790
764
  */
791
765
  error(...args) {
792
766
  const message = '◍ Saasco Error';
793
- console.error(...[`\x1b[41m\x1b[37m ${message} \x1b[0m`,
767
+ console.error(
794
768
  // Message highlighted for easy finding
795
- ...args]);
769
+ `%c ${message}`, 'background: red; color: white; padding: 2px 4px; border-radius: 2px;', ...args);
796
770
  return {
797
771
  success: false,
798
772
  message: args.join(' ')
@@ -1234,26 +1208,7 @@ const latestIdentifiesResponseSchema = tinyBirdBaseSchema.extend({
1234
1208
  }))
1235
1209
  });
1236
1210
 
1237
- function SaascoProvider({
1238
- projectId,
1239
- debug = false,
1240
- enabled = true,
1241
- proxy
1242
- }) {
1243
- react.useEffect(() => {
1244
- const saasco = new Saasco({
1245
- projectId,
1246
- debug,
1247
- enabled,
1248
- proxy
1249
- });
1250
- saasco.init();
1251
- }, [projectId, debug, enabled, proxy]);
1252
- return null;
1253
- }
1254
-
1255
1211
  exports.Saasco = Saasco;
1256
- exports.SaascoProvider = SaascoProvider;
1257
1212
  exports.TinybirdJobResponseSchema = TinybirdJobResponseSchema;
1258
1213
  exports.analyticsEventSchema = analyticsEventSchema;
1259
1214
  exports.analyticsUserRawSchema = analyticsUserRawSchema;
package/index.esm.js CHANGED
@@ -1,38 +1,8 @@
1
+ import { __awaiter } from 'tslib';
1
2
  import { v4 } from '@lukeed/uuid';
2
3
  import { z } from 'zod';
3
- import { useEffect } from 'react';
4
4
 
5
- /******************************************************************************
6
- Copyright (c) Microsoft Corporation.
7
-
8
- Permission to use, copy, modify, and/or distribute this software for any
9
- purpose with or without fee is hereby granted.
10
-
11
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
- PERFORMANCE OF THIS SOFTWARE.
18
- ***************************************************************************** */
19
-
20
- function __awaiter(thisArg, _arguments, P, generator) {
21
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
22
- return new (P || (P = Promise))(function (resolve, reject) {
23
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
24
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
25
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
26
- step((generator = generator.apply(thisArg, _arguments || [])).next());
27
- });
28
- }
29
-
30
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
31
- var e = new Error(message);
32
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
33
- };
34
-
35
- var version = "0.1.19";
5
+ var version = "0.1.20";
36
6
 
37
7
  const timezones = {
38
8
  'Asia/Barnaul': 'RU',
@@ -605,6 +575,8 @@ class Saasco {
605
575
  window.saasco = this;
606
576
  }
607
577
  this.log('Saasco initialized', this.config);
578
+ if (this.config.debug) this.log('Debug mode active. This will log all events to the console.');
579
+ if (!this.config.enabled) this.log('Analytics is disabled. No requests will be sent to the server.');
608
580
  this.initiAutoPageTracking();
609
581
  this.isInitialized = true;
610
582
  }
@@ -738,9 +710,11 @@ class Saasco {
738
710
  return __awaiter(this, void 0, void 0, function* () {
739
711
  const base = this.config.proxy || 'https://www.saasco.com/api/';
740
712
  const url = `${base}${path}`;
741
- const logMessage = data.action === 'Page View' ? `Page View ${window.location.pathname}` // if its a page view, include pathname in console log
742
- : data.action || path;
743
- this.log(logMessage, data);
713
+ if (data.action === 'Page View') {
714
+ this.log('Page View', window.location.href, data);
715
+ } else {
716
+ this.log(data.action || path, data);
717
+ }
744
718
  // If analytics is disabled, don't send the request
745
719
  if (this.config.enabled === false) return {
746
720
  success: false,
@@ -777,18 +751,18 @@ class Saasco {
777
751
  log(...args) {
778
752
  if (!this.config.debug) return;
779
753
  const message = '◍ Saasco Debug';
780
- console.info(...[`\x1b[47m\x1b[30m ${message} \x1b[0m`,
754
+ console.info(
781
755
  // Message highlighted for easy finding
782
- ...args]);
756
+ `%c ${message}`, 'background: #eee; color: #000; padding: 2px 4px; border-radius: 2px;', ...args);
783
757
  }
784
758
  /**
785
759
  * @param args Arguments to be logged
786
760
  */
787
761
  error(...args) {
788
762
  const message = '◍ Saasco Error';
789
- console.error(...[`\x1b[41m\x1b[37m ${message} \x1b[0m`,
763
+ console.error(
790
764
  // Message highlighted for easy finding
791
- ...args]);
765
+ `%c ${message}`, 'background: red; color: white; padding: 2px 4px; border-radius: 2px;', ...args);
792
766
  return {
793
767
  success: false,
794
768
  message: args.join(' ')
@@ -1230,22 +1204,4 @@ const latestIdentifiesResponseSchema = tinyBirdBaseSchema.extend({
1230
1204
  }))
1231
1205
  });
1232
1206
 
1233
- function SaascoProvider({
1234
- projectId,
1235
- debug = false,
1236
- enabled = true,
1237
- proxy
1238
- }) {
1239
- useEffect(() => {
1240
- const saasco = new Saasco({
1241
- projectId,
1242
- debug,
1243
- enabled,
1244
- proxy
1245
- });
1246
- saasco.init();
1247
- }, [projectId, debug, enabled, proxy]);
1248
- return null;
1249
- }
1250
-
1251
- export { Saasco, SaascoProvider, TinybirdJobResponseSchema, analyticsEventSchema, analyticsUserRawSchema, analyticsUserSchema, baseTopRequestSchema, browserContextSchema, coerceReservedProperties, contactPropertiesSchema, createTrackedEventTypeSchema, currentUsersRequestSchema, currentUsersResponseSchema, getAnalyticsUserParamsSchema, getBrowserContext, idenfitySchema, kpiSchema, kpisRequestSchema, kpisResponseSchema, latestEventItemSchema, latestEventsRequestSchema, latestEventsResponseSchema, latestIdentifiesRequestSchema, latestIdentifiesResponseSchema, listUsersParamsSchema, reservedPropertiesSchema, serverContextSchema, tbAny, timezones, tinyBirdBaseSchema, topActionsResponseSchema, topBrowsersResponseSchema, topDevicesResponseSchema, topLocationsResponseSchema, topPagesResponseSchema, topSourcesResponseSchema, topSourcesSchema, trackedEventSchema, trackedEventTypesSchema, userEventsResponseSchema };
1207
+ export { Saasco, TinybirdJobResponseSchema, analyticsEventSchema, analyticsUserRawSchema, analyticsUserSchema, baseTopRequestSchema, browserContextSchema, coerceReservedProperties, contactPropertiesSchema, createTrackedEventTypeSchema, currentUsersRequestSchema, currentUsersResponseSchema, getAnalyticsUserParamsSchema, getBrowserContext, idenfitySchema, kpiSchema, kpisRequestSchema, kpisResponseSchema, latestEventItemSchema, latestEventsRequestSchema, latestEventsResponseSchema, latestIdentifiesRequestSchema, latestIdentifiesResponseSchema, listUsersParamsSchema, reservedPropertiesSchema, serverContextSchema, tbAny, timezones, tinyBirdBaseSchema, topActionsResponseSchema, topBrowsersResponseSchema, topDevicesResponseSchema, topLocationsResponseSchema, topPagesResponseSchema, topSourcesResponseSchema, topSourcesSchema, trackedEventSchema, trackedEventTypesSchema, userEventsResponseSchema };
package/package.json CHANGED
@@ -1,16 +1,11 @@
1
1
  {
2
2
  "name": "saasco-sdk",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "dependencies": {
5
+ "tslib": "^2.3.0",
5
6
  "@lukeed/uuid": "^2.0.1",
6
7
  "zod": "^3.22.4"
7
8
  },
8
- "peerDependencies": {
9
- "react": "^18.0.0"
10
- },
11
- "devDependencies": {
12
- "tslib": "^2.3.0"
13
- },
14
9
  "main": "./index.cjs.js",
15
10
  "typings": "./src/index.d.ts",
16
11
  "module": "./index.esm.js"
package/src/index.d.ts CHANGED
@@ -4,4 +4,3 @@ export * from './lib/getBrowserContext';
4
4
  export * from './lib/timezones';
5
5
  export * from './lib/tracking';
6
6
  export * from './lib/types';
7
- export * from './lib/nextjs';
@@ -1,7 +0,0 @@
1
- export type SaascoProviderProps = {
2
- projectId: string;
3
- debug?: boolean;
4
- enabled?: boolean;
5
- proxy?: string;
6
- };
7
- export declare function SaascoProvider({ projectId, debug, enabled, proxy, }: SaascoProviderProps): React.ReactElement | null;
@@ -1 +0,0 @@
1
- export * from './SaascoProvider';