saasco-sdk 0.1.19 → 0.1.21
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 +5 -5
- package/index.cjs.js +14 -474
- package/index.esm.js +14 -438
- package/package.json +2 -7
- package/src/index.d.ts +1 -4
- package/src/lib/getBrowserContext.d.ts +1 -1
- package/src/lib/tracking/types.d.ts +0 -2762
- package/src/lib/coerceReservedProperties.d.ts +0 -2
- package/src/lib/nextjs/SaascoProvider.d.ts +0 -7
- package/src/lib/nextjs/index.d.ts +0 -1
- package/src/lib/types.d.ts +0 -1971
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.21";
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
|
|
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(
|
|
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(
|
|
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(' ')
|
|
@@ -837,107 +811,6 @@ class Saasco {
|
|
|
837
811
|
}
|
|
838
812
|
}
|
|
839
813
|
|
|
840
|
-
function coerceReservedProperties(properties) {
|
|
841
|
-
const coerce = [{
|
|
842
|
-
key: 'age',
|
|
843
|
-
coerceFrom: ['age', 'age_value', 'ageValue', 'user_age', 'userAge', 'user_age_value', 'userAgeValue', 'age_of_user', 'ageOfUser', 'age_in_years', 'ageInYears', 'years_old', 'yearsOld', 'age_years', 'ageYears'],
|
|
844
|
-
schema: z.coerce.number().optional()
|
|
845
|
-
}, {
|
|
846
|
-
key: 'avatar',
|
|
847
|
-
coerceFrom: ['avatar', 'user_avatar', 'userAvatar', 'avatar_url', 'avatarUrl', 'profile_picture', 'profilePicture', 'picture', 'user_picture', 'userPicture', 'profile_pic', 'profilePic', 'pic', 'user_pic', 'userPic', 'image', 'user_image', 'userImage', 'profile_image', 'profileImage', 'profile_image_url', 'profileImageUrl', 'profile_pic_url', 'profilePicUrl', 'pic_url', 'picUrl', 'image_url', 'imageUrl', 'user_image_url', 'userImageUrl', 'user_pic_url', 'userPicUrl', 'profile_pic_url', 'profilePicUrl', 'pic_url', 'picUrl', 'image_url', 'imageUrl', 'user_image_url', 'userImageUrl', 'user_pic_url', 'userPicUrl'],
|
|
848
|
-
schema: z.coerce.string().url().optional()
|
|
849
|
-
}, {
|
|
850
|
-
key: 'birthday',
|
|
851
|
-
coerceFrom: ['birthday', 'birth_date', 'birthDate', 'date_of_birth', 'dateOfBirth', 'dob', 'Dob', 'birth_day', 'birthDay']
|
|
852
|
-
}, {
|
|
853
|
-
key: 'createdAt',
|
|
854
|
-
coerceFrom: ['createdAt', 'created_at', 'created', 'createdDate', 'created_date', 'dateCreated', 'date_created', 'date_created_at', 'dateCreatedAt', 'date_created_at', 'dateCreated', 'date_created'],
|
|
855
|
-
schema: z.coerce.date().optional()
|
|
856
|
-
}, {
|
|
857
|
-
key: 'description',
|
|
858
|
-
coerceFrom: ['description', 'bio', 'about', 'about_me', 'aboutMe', 'user_description', 'userDescription', 'profile_description', 'profileDescription']
|
|
859
|
-
}, {
|
|
860
|
-
key: 'email',
|
|
861
|
-
coerceFrom: ['email', 'user_email', 'userEmail', 'email_address', 'emailAddress', 'e_mail', 'E_Mail', 'mail', 'Mail', 'contact_email', 'contactEmail', 'primary_email', 'primaryEmail'],
|
|
862
|
-
schema: z.coerce.string().email().optional()
|
|
863
|
-
}, {
|
|
864
|
-
key: 'firstName',
|
|
865
|
-
coerceFrom: ['first_name', 'firstName', 'firstname', 'given_name', 'givenName', 'user_first_name', 'userFirstName', 'name_first', 'nameFirst', 'f_name', 'fName']
|
|
866
|
-
}, {
|
|
867
|
-
key: 'gender',
|
|
868
|
-
coerceFrom: ['gender', 'user_gender', 'userGender', 'sex', 'user_sex', 'userSex']
|
|
869
|
-
}, {
|
|
870
|
-
key: 'lastName',
|
|
871
|
-
coerceFrom: ['last_name', 'lastName', 'lastname', 'surname', 'user_last_name', 'userLastName', 'name_last', 'nameLast', 'l_name', 'lName']
|
|
872
|
-
}, {
|
|
873
|
-
key: 'name',
|
|
874
|
-
coerceFrom: ['name', 'full_name', 'fullName', 'user_name', 'userName', 'complete_name', 'completeName']
|
|
875
|
-
}, {
|
|
876
|
-
key: 'phone',
|
|
877
|
-
coerceFrom: ['phone', 'phone_number', 'phoneNumber', 'mobile', 'mobile_number', 'mobileNumber', 'contact_number', 'contactNumber', 'tel', 'telephone']
|
|
878
|
-
}, {
|
|
879
|
-
key: 'title',
|
|
880
|
-
coerceFrom: ['title', 'user_title', 'userTitle', 'position', 'job_title', 'jobTitle']
|
|
881
|
-
}, {
|
|
882
|
-
key: 'username',
|
|
883
|
-
coerceFrom: ['username', 'user_name', 'userName', 'user_login', 'userLogin', 'account_name', 'accountName', 'screen_name', 'screenName', 'handle']
|
|
884
|
-
}, {
|
|
885
|
-
key: 'website',
|
|
886
|
-
coerceFrom: ['website', 'web_site', 'site', 'web', 'personal_website', 'personalWebsite', 'company_website', 'companyWebsite'],
|
|
887
|
-
schema: z.coerce.string().url().optional()
|
|
888
|
-
}, {
|
|
889
|
-
key: 'displayName',
|
|
890
|
-
coerceFrom: ['display_name', 'displayName', 'user_display_name', 'userDisplayName', 'full_name', 'fullName', 'user_full_name', 'userFullName', 'complete_name', 'completeName', 'user_complete_name', 'userCompleteName', 'name', 'username']
|
|
891
|
-
}, {
|
|
892
|
-
key: '$stripeCustomerId',
|
|
893
|
-
coerceFrom: ['stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId']
|
|
894
|
-
}];
|
|
895
|
-
return coerce.reduce((acc, {
|
|
896
|
-
key,
|
|
897
|
-
coerceFrom,
|
|
898
|
-
schema
|
|
899
|
-
}) => {
|
|
900
|
-
const coercedValue = coerceValue(properties, coerceFrom, schema);
|
|
901
|
-
if (coercedValue) acc[key] = coercedValue;
|
|
902
|
-
if (!coercedValue && key === 'displayName') {
|
|
903
|
-
let displayName = '';
|
|
904
|
-
if (acc['firstName']) {
|
|
905
|
-
displayName = `${acc['firstName'] || ''} ${acc['lastName'] || ''}`.trim();
|
|
906
|
-
} else if (acc['username'] && typeof acc['username'] === 'string') {
|
|
907
|
-
displayName = acc['username'];
|
|
908
|
-
} else if (acc['name'] && typeof acc['name'] === 'string') {
|
|
909
|
-
displayName = acc['name'];
|
|
910
|
-
}
|
|
911
|
-
if (displayName) acc[key] = displayName;
|
|
912
|
-
}
|
|
913
|
-
return acc;
|
|
914
|
-
}, properties);
|
|
915
|
-
}
|
|
916
|
-
/**
|
|
917
|
-
* Coerces the first non-null value from the properties object
|
|
918
|
-
* @param properties
|
|
919
|
-
* @param keys Provided in priority order, the first to match will return
|
|
920
|
-
* @returns
|
|
921
|
-
*/
|
|
922
|
-
function coerceValue(properties, keys, schema) {
|
|
923
|
-
let coercedValue = null;
|
|
924
|
-
for (const key of keys) {
|
|
925
|
-
if (properties[key] !== undefined) {
|
|
926
|
-
if (!schema) {
|
|
927
|
-
coercedValue = properties[key];
|
|
928
|
-
break;
|
|
929
|
-
} else {
|
|
930
|
-
const result = schema.safeParse(properties[key]);
|
|
931
|
-
if (result.success) {
|
|
932
|
-
coercedValue = properties[key];
|
|
933
|
-
break;
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
return coercedValue;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
814
|
const browserContextSchema = z.object({
|
|
942
815
|
$locale: z.string(),
|
|
943
816
|
$location: z.string(),
|
|
@@ -950,302 +823,5 @@ const browserContextSchema = z.object({
|
|
|
950
823
|
$title: z.string(),
|
|
951
824
|
$userAgent: z.string()
|
|
952
825
|
});
|
|
953
|
-
const serverContextSchema = z.object({
|
|
954
|
-
$city: z.string().optional(),
|
|
955
|
-
$country: z.string().optional(),
|
|
956
|
-
$continent: z.string().optional(),
|
|
957
|
-
$latitude: z.number().optional(),
|
|
958
|
-
$longitude: z.number().optional(),
|
|
959
|
-
$timezone: z.string().optional(),
|
|
960
|
-
$userAgent: z.string().optional(),
|
|
961
|
-
$referrer: z.string().optional(),
|
|
962
|
-
$ip: z.string().optional(),
|
|
963
|
-
$processedAt: z.string().datetime().optional(),
|
|
964
|
-
$identityHash: z.string().optional()
|
|
965
|
-
});
|
|
966
|
-
const trackedEventTypesSchema = z.enum(['SHORTLINK_REDIRECT']);
|
|
967
|
-
const trackedEventSchema = z.object({
|
|
968
|
-
id: z.string().uuid(),
|
|
969
|
-
timestamp: z.string().datetime(),
|
|
970
|
-
projectId: z.string(),
|
|
971
|
-
version: z.string(),
|
|
972
|
-
type: trackedEventTypesSchema,
|
|
973
|
-
payload: z.object({
|
|
974
|
-
browserContext: browserContextSchema.optional(),
|
|
975
|
-
serverContext: serverContextSchema.optional(),
|
|
976
|
-
properties: z.record(z.string(), z.any()).optional()
|
|
977
|
-
})
|
|
978
|
-
});
|
|
979
|
-
/**
|
|
980
|
-
* Creates a zod for tracking any type of event.
|
|
981
|
-
* Includes the base tracking schema and extends with any new schema
|
|
982
|
-
* @param type
|
|
983
|
-
* @param payloadSchema
|
|
984
|
-
* @returns
|
|
985
|
-
*/
|
|
986
|
-
function createTrackedEventTypeSchema(type, payloadSchema) {
|
|
987
|
-
const typeSchema = z.literal(type);
|
|
988
|
-
return trackedEventSchema.extend({
|
|
989
|
-
type: typeSchema,
|
|
990
|
-
payload: z.object(Object.assign(Object.assign({}, trackedEventSchema.shape.payload.shape), {
|
|
991
|
-
properties: payloadSchema
|
|
992
|
-
}))
|
|
993
|
-
});
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
const tbAny = z.union([z.string(), z.number(), z.array(z.union([z.string(), z.number()]))]);
|
|
997
|
-
const tinyBirdBaseSchema = z.object({
|
|
998
|
-
meta: z.array(z.object({
|
|
999
|
-
name: z.string(),
|
|
1000
|
-
type: z.string()
|
|
1001
|
-
})),
|
|
1002
|
-
statistics: z.object({
|
|
1003
|
-
elapsed: z.number(),
|
|
1004
|
-
rows_read: z.number(),
|
|
1005
|
-
bytes_read: z.number()
|
|
1006
|
-
}),
|
|
1007
|
-
rows: z.number()
|
|
1008
|
-
});
|
|
1009
|
-
const TinybirdJobResponseSchema = z.object({
|
|
1010
|
-
id: z.string(),
|
|
1011
|
-
job_id: z.string(),
|
|
1012
|
-
job_url: z.string().url(),
|
|
1013
|
-
job: z.object({
|
|
1014
|
-
kind: z.string(),
|
|
1015
|
-
id: z.string(),
|
|
1016
|
-
job_id: z.string(),
|
|
1017
|
-
status: z.string(),
|
|
1018
|
-
created_at: z.string(),
|
|
1019
|
-
updated_at: z.string(),
|
|
1020
|
-
started_at: z.string().nullable(),
|
|
1021
|
-
is_cancellable: z.boolean(),
|
|
1022
|
-
datasource: z.object({
|
|
1023
|
-
id: z.string(),
|
|
1024
|
-
name: z.string()
|
|
1025
|
-
}),
|
|
1026
|
-
delete_condition: z.string().optional()
|
|
1027
|
-
}),
|
|
1028
|
-
status: z.string(),
|
|
1029
|
-
delete_id: z.string().optional(),
|
|
1030
|
-
import_id: z.string().optional()
|
|
1031
|
-
});
|
|
1032
|
-
const latestEventsRequestSchema = z.object({
|
|
1033
|
-
projectId: z.string(),
|
|
1034
|
-
limit: z.number().optional(),
|
|
1035
|
-
payload: z.boolean().optional(),
|
|
1036
|
-
distinctId: z.string().optional(),
|
|
1037
|
-
action: z.string().optional()
|
|
1038
|
-
});
|
|
1039
|
-
const latestEventItemSchema = z.object({
|
|
1040
|
-
id: z.string(),
|
|
1041
|
-
timestamp: z.string(),
|
|
1042
|
-
action: z.string(),
|
|
1043
|
-
location: z.string(),
|
|
1044
|
-
referrer: z.string(),
|
|
1045
|
-
href: z.string(),
|
|
1046
|
-
device: z.string(),
|
|
1047
|
-
browser: z.string(),
|
|
1048
|
-
payload: z.string().optional(),
|
|
1049
|
-
distinctId: z.string().optional(),
|
|
1050
|
-
unique: z.boolean().optional()
|
|
1051
|
-
});
|
|
1052
|
-
const latestEventsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1053
|
-
data: z.array(latestEventItemSchema)
|
|
1054
|
-
});
|
|
1055
|
-
const kpisRequestSchema = z.object({
|
|
1056
|
-
projectId: z.string(),
|
|
1057
|
-
dateTo: z.string().optional(),
|
|
1058
|
-
dateFrom: z.string().optional(),
|
|
1059
|
-
referrer: z.string().optional(),
|
|
1060
|
-
location: z.string().optional()
|
|
1061
|
-
});
|
|
1062
|
-
const kpiSchema = z.object({
|
|
1063
|
-
date: z.string(),
|
|
1064
|
-
users: z.number(),
|
|
1065
|
-
sessions: z.number(),
|
|
1066
|
-
pageViews: z.number(),
|
|
1067
|
-
events: z.number(),
|
|
1068
|
-
bounceRate: z.nullable(z.number()),
|
|
1069
|
-
avgSessionSec: z.number()
|
|
1070
|
-
});
|
|
1071
|
-
const kpisResponseSchema = tinyBirdBaseSchema.extend({
|
|
1072
|
-
data: z.array(kpiSchema)
|
|
1073
|
-
});
|
|
1074
|
-
const baseTopRequestSchema = z.object({
|
|
1075
|
-
projectId: z.string(),
|
|
1076
|
-
dateTo: z.string().optional(),
|
|
1077
|
-
dateFrom: z.string().optional(),
|
|
1078
|
-
limit: z.number().optional(),
|
|
1079
|
-
skip: z.number().optional(),
|
|
1080
|
-
referrer: z.string().optional(),
|
|
1081
|
-
location: z.string().optional()
|
|
1082
|
-
});
|
|
1083
|
-
const topPagesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1084
|
-
data: z.array(z.object({
|
|
1085
|
-
pathname: z.string(),
|
|
1086
|
-
users: z.number(),
|
|
1087
|
-
events: z.number()
|
|
1088
|
-
}))
|
|
1089
|
-
});
|
|
1090
|
-
const topLocationsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1091
|
-
data: z.array(z.object({
|
|
1092
|
-
location: z.string(),
|
|
1093
|
-
users: z.number(),
|
|
1094
|
-
sessions: z.number(),
|
|
1095
|
-
pageViews: z.number(),
|
|
1096
|
-
bounceRate: z.nullable(z.number()),
|
|
1097
|
-
avgSessionSec: z.number()
|
|
1098
|
-
}))
|
|
1099
|
-
});
|
|
1100
|
-
const topDevicesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1101
|
-
data: z.array(z.object({
|
|
1102
|
-
device: z.string(),
|
|
1103
|
-
visits: z.number(),
|
|
1104
|
-
hits: z.number(),
|
|
1105
|
-
bounceRate: z.nullable(z.number()),
|
|
1106
|
-
avgSessionSec: z.number()
|
|
1107
|
-
}))
|
|
1108
|
-
});
|
|
1109
|
-
const topBrowsersResponseSchema = tinyBirdBaseSchema.extend({
|
|
1110
|
-
data: z.array(z.object({
|
|
1111
|
-
browser: z.string(),
|
|
1112
|
-
visits: z.number(),
|
|
1113
|
-
hits: z.number(),
|
|
1114
|
-
bounceRate: z.nullable(z.number()),
|
|
1115
|
-
avgSessionSec: z.number()
|
|
1116
|
-
}))
|
|
1117
|
-
});
|
|
1118
|
-
const topSourcesSchema = z.object({
|
|
1119
|
-
referrer: z.string(),
|
|
1120
|
-
users: z.number(),
|
|
1121
|
-
sessions: z.number(),
|
|
1122
|
-
pageViews: z.number(),
|
|
1123
|
-
bounceRate: z.nullable(z.number()),
|
|
1124
|
-
avgSessionSec: z.number()
|
|
1125
|
-
});
|
|
1126
|
-
const topSourcesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1127
|
-
data: z.array(topSourcesSchema)
|
|
1128
|
-
});
|
|
1129
|
-
const topActionsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1130
|
-
data: z.array(z.object({
|
|
1131
|
-
action: z.string(),
|
|
1132
|
-
users: z.number(),
|
|
1133
|
-
events: z.number()
|
|
1134
|
-
}))
|
|
1135
|
-
});
|
|
1136
|
-
const analyticsEventSchema = z.object({
|
|
1137
|
-
id: z.string(),
|
|
1138
|
-
timestamp: z.string(),
|
|
1139
|
-
projectId: z.string(),
|
|
1140
|
-
anonymousId: z.string(),
|
|
1141
|
-
sessionId: z.string(),
|
|
1142
|
-
distinctId: z.string().nullable(),
|
|
1143
|
-
version: z.string(),
|
|
1144
|
-
action: z.string(),
|
|
1145
|
-
payload: z.string()
|
|
1146
|
-
});
|
|
1147
|
-
const userEventsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1148
|
-
data: z.array(analyticsEventSchema)
|
|
1149
|
-
});
|
|
1150
|
-
const currentUsersRequestSchema = z.object({
|
|
1151
|
-
projectId: z.string(),
|
|
1152
|
-
minutes: z.number(),
|
|
1153
|
-
referrer: z.string().optional(),
|
|
1154
|
-
location: z.string().optional()
|
|
1155
|
-
});
|
|
1156
|
-
const currentUsersResponseSchema = tinyBirdBaseSchema.extend({
|
|
1157
|
-
data: z.array(z.object({
|
|
1158
|
-
visits: z.number()
|
|
1159
|
-
}))
|
|
1160
|
-
});
|
|
1161
|
-
const reservedPropertiesSchema = z.object({
|
|
1162
|
-
age: z.number().nullish(),
|
|
1163
|
-
avatar: z.string().url().nullish(),
|
|
1164
|
-
birthday: z.string().nullish(),
|
|
1165
|
-
createdAt: z.string().nullish(),
|
|
1166
|
-
description: z.string().nullish(),
|
|
1167
|
-
email: z.string().email().or(z.literal('')).nullish(),
|
|
1168
|
-
firstName: z.string().nullish(),
|
|
1169
|
-
gender: z.string().nullish(),
|
|
1170
|
-
id: z.string().nullish(),
|
|
1171
|
-
lastName: z.string().nullish(),
|
|
1172
|
-
name: z.string().nullish(),
|
|
1173
|
-
phone: z.string().nullish(),
|
|
1174
|
-
title: z.string().nullish(),
|
|
1175
|
-
username: z.string().nullish(),
|
|
1176
|
-
website: z.string().nullish(),
|
|
1177
|
-
// Default Properties
|
|
1178
|
-
$id: z.string().nullish(),
|
|
1179
|
-
$lastSeen: z.string().nullish(),
|
|
1180
|
-
$lastIdentifiedAt: z.string().nullish(),
|
|
1181
|
-
$unsubscribed: z.boolean().nullish(),
|
|
1182
|
-
$unsubscribeReason: z.enum(['manual', 'complained', 'bounced']).nullish(),
|
|
1183
|
-
// Stripe Properties
|
|
1184
|
-
$stripeCustomerId: z.string().nullish(),
|
|
1185
|
-
$stripeTotalPayments: z.number().or(z.string()).nullish(),
|
|
1186
|
-
$stripeTotalSpent: z.number().or(z.string()).nullish(),
|
|
1187
|
-
// Internal properties
|
|
1188
|
-
$_toDelete: z.boolean().nullish()
|
|
1189
|
-
});
|
|
1190
|
-
const contactPropertiesSchema = reservedPropertiesSchema.optional().and(z.record(z.union([z.string(), z.number(), z.boolean(), z.date(), z.null(), z.array(z.union([z.string(), z.number(), z.boolean(), z.date(), z.null()]))])));
|
|
1191
|
-
const analyticsUserRawSchema = z.object({
|
|
1192
|
-
timestamp: z.string(),
|
|
1193
|
-
distinctId: z.string(),
|
|
1194
|
-
projectId: z.string(),
|
|
1195
|
-
payload: z.string()
|
|
1196
|
-
});
|
|
1197
|
-
const analyticsUserSchema = analyticsUserRawSchema.omit({
|
|
1198
|
-
payload: true
|
|
1199
|
-
}).and(z.object({
|
|
1200
|
-
properties: contactPropertiesSchema
|
|
1201
|
-
}));
|
|
1202
|
-
const listUsersParamsSchema = z.object({
|
|
1203
|
-
projectId: z.string(),
|
|
1204
|
-
limit: z.number().optional()
|
|
1205
|
-
});
|
|
1206
|
-
const getAnalyticsUserParamsSchema = z.object({
|
|
1207
|
-
projectId: z.string(),
|
|
1208
|
-
distinctId: z.string()
|
|
1209
|
-
});
|
|
1210
|
-
const idenfitySchema = z.object({
|
|
1211
|
-
id: z.string(),
|
|
1212
|
-
timestamp: z.string(),
|
|
1213
|
-
projectId: z.string(),
|
|
1214
|
-
distinctId: z.string(),
|
|
1215
|
-
anonymousId: z.string(),
|
|
1216
|
-
version: z.string(),
|
|
1217
|
-
payload: contactPropertiesSchema,
|
|
1218
|
-
context: z.object({
|
|
1219
|
-
active: z.boolean().optional()
|
|
1220
|
-
}).optional()
|
|
1221
|
-
});
|
|
1222
|
-
const latestIdentifiesRequestSchema = z.object({
|
|
1223
|
-
projectId: z.string(),
|
|
1224
|
-
limit: z.number().optional(),
|
|
1225
|
-
fields: z.array(z.string()).optional()
|
|
1226
|
-
});
|
|
1227
|
-
const latestIdentifiesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1228
|
-
data: z.array(z.object({
|
|
1229
|
-
properties: contactPropertiesSchema
|
|
1230
|
-
}))
|
|
1231
|
-
});
|
|
1232
|
-
|
|
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
826
|
|
|
1251
|
-
export { Saasco,
|
|
827
|
+
export { Saasco, browserContextSchema, getBrowserContext, timezones };
|
package/package.json
CHANGED
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "saasco-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
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
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
export * from './lib/analytics';
|
|
2
|
-
export * from './lib/coerceReservedProperties';
|
|
3
2
|
export * from './lib/getBrowserContext';
|
|
4
|
-
export * from './lib/timezones';
|
|
5
3
|
export * from './lib/tracking';
|
|
6
|
-
export * from './lib/
|
|
7
|
-
export * from './lib/nextjs';
|
|
4
|
+
export * from './lib/timezones';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { BrowserContext } from './tracking
|
|
1
|
+
import { BrowserContext } from './tracking';
|
|
2
2
|
export declare function getBrowserContext(): BrowserContext | undefined;
|