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/README.md
CHANGED
|
@@ -292,7 +292,7 @@ Reserved events are common events that happen during the lifecycle of a user, wi
|
|
|
292
292
|
- [Signed In](#signed-in)
|
|
293
293
|
- [Signed Out](#signed-out)
|
|
294
294
|
- [Trial Started](#trial-started)
|
|
295
|
-
- [Trial
|
|
295
|
+
- [Trial Ended](#trial-ended)
|
|
296
296
|
- [Payment Completed](#payment-completed)
|
|
297
297
|
- [Subscription Started](#subscription-started)
|
|
298
298
|
- [Subscription Cancelled](#subscription-cancelled)
|
|
@@ -355,9 +355,9 @@ Example:
|
|
|
355
355
|
saasco.track('Trial Started', { duration: 14, type: 'optOut' });
|
|
356
356
|
```
|
|
357
357
|
|
|
358
|
-
#### Trial
|
|
358
|
+
#### Trial Ended
|
|
359
359
|
|
|
360
|
-
Event triggered when a
|
|
360
|
+
Event triggered when a users trial ends.
|
|
361
361
|
| Property | Description |
|
|
362
362
|
|-------------------|---------------------------------------------------------------------|
|
|
363
363
|
| `daysLeftInTrial`| If a user manual upgrades before the end of the trial you can record this here|
|
|
@@ -365,10 +365,10 @@ Event triggered when a user successfully completes a trial.
|
|
|
365
365
|
Example:
|
|
366
366
|
|
|
367
367
|
```jsx
|
|
368
|
-
saasco.track('Trial
|
|
368
|
+
saasco.track('Trial Ended', { daysLeftInTrial: 4 });
|
|
369
369
|
```
|
|
370
370
|
|
|
371
|
-
#### Payment
|
|
371
|
+
#### Payment Ended
|
|
372
372
|
|
|
373
373
|
Event triggered when a payment is completed.
|
|
374
374
|
This is may be called on the server side after a confirmation webhook.
|
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.21";
|
|
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
|
-
|
|
746
|
-
|
|
747
|
-
|
|
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(
|
|
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(
|
|
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(' ')
|
|
@@ -841,107 +815,6 @@ class Saasco {
|
|
|
841
815
|
}
|
|
842
816
|
}
|
|
843
817
|
|
|
844
|
-
function coerceReservedProperties(properties) {
|
|
845
|
-
const coerce = [{
|
|
846
|
-
key: 'age',
|
|
847
|
-
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'],
|
|
848
|
-
schema: zod.z.coerce.number().optional()
|
|
849
|
-
}, {
|
|
850
|
-
key: 'avatar',
|
|
851
|
-
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'],
|
|
852
|
-
schema: zod.z.coerce.string().url().optional()
|
|
853
|
-
}, {
|
|
854
|
-
key: 'birthday',
|
|
855
|
-
coerceFrom: ['birthday', 'birth_date', 'birthDate', 'date_of_birth', 'dateOfBirth', 'dob', 'Dob', 'birth_day', 'birthDay']
|
|
856
|
-
}, {
|
|
857
|
-
key: 'createdAt',
|
|
858
|
-
coerceFrom: ['createdAt', 'created_at', 'created', 'createdDate', 'created_date', 'dateCreated', 'date_created', 'date_created_at', 'dateCreatedAt', 'date_created_at', 'dateCreated', 'date_created'],
|
|
859
|
-
schema: zod.z.coerce.date().optional()
|
|
860
|
-
}, {
|
|
861
|
-
key: 'description',
|
|
862
|
-
coerceFrom: ['description', 'bio', 'about', 'about_me', 'aboutMe', 'user_description', 'userDescription', 'profile_description', 'profileDescription']
|
|
863
|
-
}, {
|
|
864
|
-
key: 'email',
|
|
865
|
-
coerceFrom: ['email', 'user_email', 'userEmail', 'email_address', 'emailAddress', 'e_mail', 'E_Mail', 'mail', 'Mail', 'contact_email', 'contactEmail', 'primary_email', 'primaryEmail'],
|
|
866
|
-
schema: zod.z.coerce.string().email().optional()
|
|
867
|
-
}, {
|
|
868
|
-
key: 'firstName',
|
|
869
|
-
coerceFrom: ['first_name', 'firstName', 'firstname', 'given_name', 'givenName', 'user_first_name', 'userFirstName', 'name_first', 'nameFirst', 'f_name', 'fName']
|
|
870
|
-
}, {
|
|
871
|
-
key: 'gender',
|
|
872
|
-
coerceFrom: ['gender', 'user_gender', 'userGender', 'sex', 'user_sex', 'userSex']
|
|
873
|
-
}, {
|
|
874
|
-
key: 'lastName',
|
|
875
|
-
coerceFrom: ['last_name', 'lastName', 'lastname', 'surname', 'user_last_name', 'userLastName', 'name_last', 'nameLast', 'l_name', 'lName']
|
|
876
|
-
}, {
|
|
877
|
-
key: 'name',
|
|
878
|
-
coerceFrom: ['name', 'full_name', 'fullName', 'user_name', 'userName', 'complete_name', 'completeName']
|
|
879
|
-
}, {
|
|
880
|
-
key: 'phone',
|
|
881
|
-
coerceFrom: ['phone', 'phone_number', 'phoneNumber', 'mobile', 'mobile_number', 'mobileNumber', 'contact_number', 'contactNumber', 'tel', 'telephone']
|
|
882
|
-
}, {
|
|
883
|
-
key: 'title',
|
|
884
|
-
coerceFrom: ['title', 'user_title', 'userTitle', 'position', 'job_title', 'jobTitle']
|
|
885
|
-
}, {
|
|
886
|
-
key: 'username',
|
|
887
|
-
coerceFrom: ['username', 'user_name', 'userName', 'user_login', 'userLogin', 'account_name', 'accountName', 'screen_name', 'screenName', 'handle']
|
|
888
|
-
}, {
|
|
889
|
-
key: 'website',
|
|
890
|
-
coerceFrom: ['website', 'web_site', 'site', 'web', 'personal_website', 'personalWebsite', 'company_website', 'companyWebsite'],
|
|
891
|
-
schema: zod.z.coerce.string().url().optional()
|
|
892
|
-
}, {
|
|
893
|
-
key: 'displayName',
|
|
894
|
-
coerceFrom: ['display_name', 'displayName', 'user_display_name', 'userDisplayName', 'full_name', 'fullName', 'user_full_name', 'userFullName', 'complete_name', 'completeName', 'user_complete_name', 'userCompleteName', 'name', 'username']
|
|
895
|
-
}, {
|
|
896
|
-
key: '$stripeCustomerId',
|
|
897
|
-
coerceFrom: ['stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId', 'stripe_customer_id', 'stripeCustomerId']
|
|
898
|
-
}];
|
|
899
|
-
return coerce.reduce((acc, {
|
|
900
|
-
key,
|
|
901
|
-
coerceFrom,
|
|
902
|
-
schema
|
|
903
|
-
}) => {
|
|
904
|
-
const coercedValue = coerceValue(properties, coerceFrom, schema);
|
|
905
|
-
if (coercedValue) acc[key] = coercedValue;
|
|
906
|
-
if (!coercedValue && key === 'displayName') {
|
|
907
|
-
let displayName = '';
|
|
908
|
-
if (acc['firstName']) {
|
|
909
|
-
displayName = `${acc['firstName'] || ''} ${acc['lastName'] || ''}`.trim();
|
|
910
|
-
} else if (acc['username'] && typeof acc['username'] === 'string') {
|
|
911
|
-
displayName = acc['username'];
|
|
912
|
-
} else if (acc['name'] && typeof acc['name'] === 'string') {
|
|
913
|
-
displayName = acc['name'];
|
|
914
|
-
}
|
|
915
|
-
if (displayName) acc[key] = displayName;
|
|
916
|
-
}
|
|
917
|
-
return acc;
|
|
918
|
-
}, properties);
|
|
919
|
-
}
|
|
920
|
-
/**
|
|
921
|
-
* Coerces the first non-null value from the properties object
|
|
922
|
-
* @param properties
|
|
923
|
-
* @param keys Provided in priority order, the first to match will return
|
|
924
|
-
* @returns
|
|
925
|
-
*/
|
|
926
|
-
function coerceValue(properties, keys, schema) {
|
|
927
|
-
let coercedValue = null;
|
|
928
|
-
for (const key of keys) {
|
|
929
|
-
if (properties[key] !== undefined) {
|
|
930
|
-
if (!schema) {
|
|
931
|
-
coercedValue = properties[key];
|
|
932
|
-
break;
|
|
933
|
-
} else {
|
|
934
|
-
const result = schema.safeParse(properties[key]);
|
|
935
|
-
if (result.success) {
|
|
936
|
-
coercedValue = properties[key];
|
|
937
|
-
break;
|
|
938
|
-
}
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
return coercedValue;
|
|
943
|
-
}
|
|
944
|
-
|
|
945
818
|
const browserContextSchema = zod.z.object({
|
|
946
819
|
$locale: zod.z.string(),
|
|
947
820
|
$location: zod.z.string(),
|
|
@@ -954,341 +827,8 @@ const browserContextSchema = zod.z.object({
|
|
|
954
827
|
$title: zod.z.string(),
|
|
955
828
|
$userAgent: zod.z.string()
|
|
956
829
|
});
|
|
957
|
-
const serverContextSchema = zod.z.object({
|
|
958
|
-
$city: zod.z.string().optional(),
|
|
959
|
-
$country: zod.z.string().optional(),
|
|
960
|
-
$continent: zod.z.string().optional(),
|
|
961
|
-
$latitude: zod.z.number().optional(),
|
|
962
|
-
$longitude: zod.z.number().optional(),
|
|
963
|
-
$timezone: zod.z.string().optional(),
|
|
964
|
-
$userAgent: zod.z.string().optional(),
|
|
965
|
-
$referrer: zod.z.string().optional(),
|
|
966
|
-
$ip: zod.z.string().optional(),
|
|
967
|
-
$processedAt: zod.z.string().datetime().optional(),
|
|
968
|
-
$identityHash: zod.z.string().optional()
|
|
969
|
-
});
|
|
970
|
-
const trackedEventTypesSchema = zod.z.enum(['SHORTLINK_REDIRECT']);
|
|
971
|
-
const trackedEventSchema = zod.z.object({
|
|
972
|
-
id: zod.z.string().uuid(),
|
|
973
|
-
timestamp: zod.z.string().datetime(),
|
|
974
|
-
projectId: zod.z.string(),
|
|
975
|
-
version: zod.z.string(),
|
|
976
|
-
type: trackedEventTypesSchema,
|
|
977
|
-
payload: zod.z.object({
|
|
978
|
-
browserContext: browserContextSchema.optional(),
|
|
979
|
-
serverContext: serverContextSchema.optional(),
|
|
980
|
-
properties: zod.z.record(zod.z.string(), zod.z.any()).optional()
|
|
981
|
-
})
|
|
982
|
-
});
|
|
983
|
-
/**
|
|
984
|
-
* Creates a zod for tracking any type of event.
|
|
985
|
-
* Includes the base tracking schema and extends with any new schema
|
|
986
|
-
* @param type
|
|
987
|
-
* @param payloadSchema
|
|
988
|
-
* @returns
|
|
989
|
-
*/
|
|
990
|
-
function createTrackedEventTypeSchema(type, payloadSchema) {
|
|
991
|
-
const typeSchema = zod.z.literal(type);
|
|
992
|
-
return trackedEventSchema.extend({
|
|
993
|
-
type: typeSchema,
|
|
994
|
-
payload: zod.z.object(Object.assign(Object.assign({}, trackedEventSchema.shape.payload.shape), {
|
|
995
|
-
properties: payloadSchema
|
|
996
|
-
}))
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
|
|
1000
|
-
const tbAny = zod.z.union([zod.z.string(), zod.z.number(), zod.z.array(zod.z.union([zod.z.string(), zod.z.number()]))]);
|
|
1001
|
-
const tinyBirdBaseSchema = zod.z.object({
|
|
1002
|
-
meta: zod.z.array(zod.z.object({
|
|
1003
|
-
name: zod.z.string(),
|
|
1004
|
-
type: zod.z.string()
|
|
1005
|
-
})),
|
|
1006
|
-
statistics: zod.z.object({
|
|
1007
|
-
elapsed: zod.z.number(),
|
|
1008
|
-
rows_read: zod.z.number(),
|
|
1009
|
-
bytes_read: zod.z.number()
|
|
1010
|
-
}),
|
|
1011
|
-
rows: zod.z.number()
|
|
1012
|
-
});
|
|
1013
|
-
const TinybirdJobResponseSchema = zod.z.object({
|
|
1014
|
-
id: zod.z.string(),
|
|
1015
|
-
job_id: zod.z.string(),
|
|
1016
|
-
job_url: zod.z.string().url(),
|
|
1017
|
-
job: zod.z.object({
|
|
1018
|
-
kind: zod.z.string(),
|
|
1019
|
-
id: zod.z.string(),
|
|
1020
|
-
job_id: zod.z.string(),
|
|
1021
|
-
status: zod.z.string(),
|
|
1022
|
-
created_at: zod.z.string(),
|
|
1023
|
-
updated_at: zod.z.string(),
|
|
1024
|
-
started_at: zod.z.string().nullable(),
|
|
1025
|
-
is_cancellable: zod.z.boolean(),
|
|
1026
|
-
datasource: zod.z.object({
|
|
1027
|
-
id: zod.z.string(),
|
|
1028
|
-
name: zod.z.string()
|
|
1029
|
-
}),
|
|
1030
|
-
delete_condition: zod.z.string().optional()
|
|
1031
|
-
}),
|
|
1032
|
-
status: zod.z.string(),
|
|
1033
|
-
delete_id: zod.z.string().optional(),
|
|
1034
|
-
import_id: zod.z.string().optional()
|
|
1035
|
-
});
|
|
1036
|
-
const latestEventsRequestSchema = zod.z.object({
|
|
1037
|
-
projectId: zod.z.string(),
|
|
1038
|
-
limit: zod.z.number().optional(),
|
|
1039
|
-
payload: zod.z.boolean().optional(),
|
|
1040
|
-
distinctId: zod.z.string().optional(),
|
|
1041
|
-
action: zod.z.string().optional()
|
|
1042
|
-
});
|
|
1043
|
-
const latestEventItemSchema = zod.z.object({
|
|
1044
|
-
id: zod.z.string(),
|
|
1045
|
-
timestamp: zod.z.string(),
|
|
1046
|
-
action: zod.z.string(),
|
|
1047
|
-
location: zod.z.string(),
|
|
1048
|
-
referrer: zod.z.string(),
|
|
1049
|
-
href: zod.z.string(),
|
|
1050
|
-
device: zod.z.string(),
|
|
1051
|
-
browser: zod.z.string(),
|
|
1052
|
-
payload: zod.z.string().optional(),
|
|
1053
|
-
distinctId: zod.z.string().optional(),
|
|
1054
|
-
unique: zod.z.boolean().optional()
|
|
1055
|
-
});
|
|
1056
|
-
const latestEventsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1057
|
-
data: zod.z.array(latestEventItemSchema)
|
|
1058
|
-
});
|
|
1059
|
-
const kpisRequestSchema = zod.z.object({
|
|
1060
|
-
projectId: zod.z.string(),
|
|
1061
|
-
dateTo: zod.z.string().optional(),
|
|
1062
|
-
dateFrom: zod.z.string().optional(),
|
|
1063
|
-
referrer: zod.z.string().optional(),
|
|
1064
|
-
location: zod.z.string().optional()
|
|
1065
|
-
});
|
|
1066
|
-
const kpiSchema = zod.z.object({
|
|
1067
|
-
date: zod.z.string(),
|
|
1068
|
-
users: zod.z.number(),
|
|
1069
|
-
sessions: zod.z.number(),
|
|
1070
|
-
pageViews: zod.z.number(),
|
|
1071
|
-
events: zod.z.number(),
|
|
1072
|
-
bounceRate: zod.z.nullable(zod.z.number()),
|
|
1073
|
-
avgSessionSec: zod.z.number()
|
|
1074
|
-
});
|
|
1075
|
-
const kpisResponseSchema = tinyBirdBaseSchema.extend({
|
|
1076
|
-
data: zod.z.array(kpiSchema)
|
|
1077
|
-
});
|
|
1078
|
-
const baseTopRequestSchema = zod.z.object({
|
|
1079
|
-
projectId: zod.z.string(),
|
|
1080
|
-
dateTo: zod.z.string().optional(),
|
|
1081
|
-
dateFrom: zod.z.string().optional(),
|
|
1082
|
-
limit: zod.z.number().optional(),
|
|
1083
|
-
skip: zod.z.number().optional(),
|
|
1084
|
-
referrer: zod.z.string().optional(),
|
|
1085
|
-
location: zod.z.string().optional()
|
|
1086
|
-
});
|
|
1087
|
-
const topPagesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1088
|
-
data: zod.z.array(zod.z.object({
|
|
1089
|
-
pathname: zod.z.string(),
|
|
1090
|
-
users: zod.z.number(),
|
|
1091
|
-
events: zod.z.number()
|
|
1092
|
-
}))
|
|
1093
|
-
});
|
|
1094
|
-
const topLocationsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1095
|
-
data: zod.z.array(zod.z.object({
|
|
1096
|
-
location: zod.z.string(),
|
|
1097
|
-
users: zod.z.number(),
|
|
1098
|
-
sessions: zod.z.number(),
|
|
1099
|
-
pageViews: zod.z.number(),
|
|
1100
|
-
bounceRate: zod.z.nullable(zod.z.number()),
|
|
1101
|
-
avgSessionSec: zod.z.number()
|
|
1102
|
-
}))
|
|
1103
|
-
});
|
|
1104
|
-
const topDevicesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1105
|
-
data: zod.z.array(zod.z.object({
|
|
1106
|
-
device: zod.z.string(),
|
|
1107
|
-
visits: zod.z.number(),
|
|
1108
|
-
hits: zod.z.number(),
|
|
1109
|
-
bounceRate: zod.z.nullable(zod.z.number()),
|
|
1110
|
-
avgSessionSec: zod.z.number()
|
|
1111
|
-
}))
|
|
1112
|
-
});
|
|
1113
|
-
const topBrowsersResponseSchema = tinyBirdBaseSchema.extend({
|
|
1114
|
-
data: zod.z.array(zod.z.object({
|
|
1115
|
-
browser: zod.z.string(),
|
|
1116
|
-
visits: zod.z.number(),
|
|
1117
|
-
hits: zod.z.number(),
|
|
1118
|
-
bounceRate: zod.z.nullable(zod.z.number()),
|
|
1119
|
-
avgSessionSec: zod.z.number()
|
|
1120
|
-
}))
|
|
1121
|
-
});
|
|
1122
|
-
const topSourcesSchema = zod.z.object({
|
|
1123
|
-
referrer: zod.z.string(),
|
|
1124
|
-
users: zod.z.number(),
|
|
1125
|
-
sessions: zod.z.number(),
|
|
1126
|
-
pageViews: zod.z.number(),
|
|
1127
|
-
bounceRate: zod.z.nullable(zod.z.number()),
|
|
1128
|
-
avgSessionSec: zod.z.number()
|
|
1129
|
-
});
|
|
1130
|
-
const topSourcesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1131
|
-
data: zod.z.array(topSourcesSchema)
|
|
1132
|
-
});
|
|
1133
|
-
const topActionsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1134
|
-
data: zod.z.array(zod.z.object({
|
|
1135
|
-
action: zod.z.string(),
|
|
1136
|
-
users: zod.z.number(),
|
|
1137
|
-
events: zod.z.number()
|
|
1138
|
-
}))
|
|
1139
|
-
});
|
|
1140
|
-
const analyticsEventSchema = zod.z.object({
|
|
1141
|
-
id: zod.z.string(),
|
|
1142
|
-
timestamp: zod.z.string(),
|
|
1143
|
-
projectId: zod.z.string(),
|
|
1144
|
-
anonymousId: zod.z.string(),
|
|
1145
|
-
sessionId: zod.z.string(),
|
|
1146
|
-
distinctId: zod.z.string().nullable(),
|
|
1147
|
-
version: zod.z.string(),
|
|
1148
|
-
action: zod.z.string(),
|
|
1149
|
-
payload: zod.z.string()
|
|
1150
|
-
});
|
|
1151
|
-
const userEventsResponseSchema = tinyBirdBaseSchema.extend({
|
|
1152
|
-
data: zod.z.array(analyticsEventSchema)
|
|
1153
|
-
});
|
|
1154
|
-
const currentUsersRequestSchema = zod.z.object({
|
|
1155
|
-
projectId: zod.z.string(),
|
|
1156
|
-
minutes: zod.z.number(),
|
|
1157
|
-
referrer: zod.z.string().optional(),
|
|
1158
|
-
location: zod.z.string().optional()
|
|
1159
|
-
});
|
|
1160
|
-
const currentUsersResponseSchema = tinyBirdBaseSchema.extend({
|
|
1161
|
-
data: zod.z.array(zod.z.object({
|
|
1162
|
-
visits: zod.z.number()
|
|
1163
|
-
}))
|
|
1164
|
-
});
|
|
1165
|
-
const reservedPropertiesSchema = zod.z.object({
|
|
1166
|
-
age: zod.z.number().nullish(),
|
|
1167
|
-
avatar: zod.z.string().url().nullish(),
|
|
1168
|
-
birthday: zod.z.string().nullish(),
|
|
1169
|
-
createdAt: zod.z.string().nullish(),
|
|
1170
|
-
description: zod.z.string().nullish(),
|
|
1171
|
-
email: zod.z.string().email().or(zod.z.literal('')).nullish(),
|
|
1172
|
-
firstName: zod.z.string().nullish(),
|
|
1173
|
-
gender: zod.z.string().nullish(),
|
|
1174
|
-
id: zod.z.string().nullish(),
|
|
1175
|
-
lastName: zod.z.string().nullish(),
|
|
1176
|
-
name: zod.z.string().nullish(),
|
|
1177
|
-
phone: zod.z.string().nullish(),
|
|
1178
|
-
title: zod.z.string().nullish(),
|
|
1179
|
-
username: zod.z.string().nullish(),
|
|
1180
|
-
website: zod.z.string().nullish(),
|
|
1181
|
-
// Default Properties
|
|
1182
|
-
$id: zod.z.string().nullish(),
|
|
1183
|
-
$lastSeen: zod.z.string().nullish(),
|
|
1184
|
-
$lastIdentifiedAt: zod.z.string().nullish(),
|
|
1185
|
-
$unsubscribed: zod.z.boolean().nullish(),
|
|
1186
|
-
$unsubscribeReason: zod.z.enum(['manual', 'complained', 'bounced']).nullish(),
|
|
1187
|
-
// Stripe Properties
|
|
1188
|
-
$stripeCustomerId: zod.z.string().nullish(),
|
|
1189
|
-
$stripeTotalPayments: zod.z.number().or(zod.z.string()).nullish(),
|
|
1190
|
-
$stripeTotalSpent: zod.z.number().or(zod.z.string()).nullish(),
|
|
1191
|
-
// Internal properties
|
|
1192
|
-
$_toDelete: zod.z.boolean().nullish()
|
|
1193
|
-
});
|
|
1194
|
-
const contactPropertiesSchema = reservedPropertiesSchema.optional().and(zod.z.record(zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.date(), zod.z.null(), zod.z.array(zod.z.union([zod.z.string(), zod.z.number(), zod.z.boolean(), zod.z.date(), zod.z.null()]))])));
|
|
1195
|
-
const analyticsUserRawSchema = zod.z.object({
|
|
1196
|
-
timestamp: zod.z.string(),
|
|
1197
|
-
distinctId: zod.z.string(),
|
|
1198
|
-
projectId: zod.z.string(),
|
|
1199
|
-
payload: zod.z.string()
|
|
1200
|
-
});
|
|
1201
|
-
const analyticsUserSchema = analyticsUserRawSchema.omit({
|
|
1202
|
-
payload: true
|
|
1203
|
-
}).and(zod.z.object({
|
|
1204
|
-
properties: contactPropertiesSchema
|
|
1205
|
-
}));
|
|
1206
|
-
const listUsersParamsSchema = zod.z.object({
|
|
1207
|
-
projectId: zod.z.string(),
|
|
1208
|
-
limit: zod.z.number().optional()
|
|
1209
|
-
});
|
|
1210
|
-
const getAnalyticsUserParamsSchema = zod.z.object({
|
|
1211
|
-
projectId: zod.z.string(),
|
|
1212
|
-
distinctId: zod.z.string()
|
|
1213
|
-
});
|
|
1214
|
-
const idenfitySchema = zod.z.object({
|
|
1215
|
-
id: zod.z.string(),
|
|
1216
|
-
timestamp: zod.z.string(),
|
|
1217
|
-
projectId: zod.z.string(),
|
|
1218
|
-
distinctId: zod.z.string(),
|
|
1219
|
-
anonymousId: zod.z.string(),
|
|
1220
|
-
version: zod.z.string(),
|
|
1221
|
-
payload: contactPropertiesSchema,
|
|
1222
|
-
context: zod.z.object({
|
|
1223
|
-
active: zod.z.boolean().optional()
|
|
1224
|
-
}).optional()
|
|
1225
|
-
});
|
|
1226
|
-
const latestIdentifiesRequestSchema = zod.z.object({
|
|
1227
|
-
projectId: zod.z.string(),
|
|
1228
|
-
limit: zod.z.number().optional(),
|
|
1229
|
-
fields: zod.z.array(zod.z.string()).optional()
|
|
1230
|
-
});
|
|
1231
|
-
const latestIdentifiesResponseSchema = tinyBirdBaseSchema.extend({
|
|
1232
|
-
data: zod.z.array(zod.z.object({
|
|
1233
|
-
properties: contactPropertiesSchema
|
|
1234
|
-
}))
|
|
1235
|
-
});
|
|
1236
|
-
|
|
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
830
|
|
|
1255
831
|
exports.Saasco = Saasco;
|
|
1256
|
-
exports.SaascoProvider = SaascoProvider;
|
|
1257
|
-
exports.TinybirdJobResponseSchema = TinybirdJobResponseSchema;
|
|
1258
|
-
exports.analyticsEventSchema = analyticsEventSchema;
|
|
1259
|
-
exports.analyticsUserRawSchema = analyticsUserRawSchema;
|
|
1260
|
-
exports.analyticsUserSchema = analyticsUserSchema;
|
|
1261
|
-
exports.baseTopRequestSchema = baseTopRequestSchema;
|
|
1262
832
|
exports.browserContextSchema = browserContextSchema;
|
|
1263
|
-
exports.coerceReservedProperties = coerceReservedProperties;
|
|
1264
|
-
exports.contactPropertiesSchema = contactPropertiesSchema;
|
|
1265
|
-
exports.createTrackedEventTypeSchema = createTrackedEventTypeSchema;
|
|
1266
|
-
exports.currentUsersRequestSchema = currentUsersRequestSchema;
|
|
1267
|
-
exports.currentUsersResponseSchema = currentUsersResponseSchema;
|
|
1268
|
-
exports.getAnalyticsUserParamsSchema = getAnalyticsUserParamsSchema;
|
|
1269
833
|
exports.getBrowserContext = getBrowserContext;
|
|
1270
|
-
exports.idenfitySchema = idenfitySchema;
|
|
1271
|
-
exports.kpiSchema = kpiSchema;
|
|
1272
|
-
exports.kpisRequestSchema = kpisRequestSchema;
|
|
1273
|
-
exports.kpisResponseSchema = kpisResponseSchema;
|
|
1274
|
-
exports.latestEventItemSchema = latestEventItemSchema;
|
|
1275
|
-
exports.latestEventsRequestSchema = latestEventsRequestSchema;
|
|
1276
|
-
exports.latestEventsResponseSchema = latestEventsResponseSchema;
|
|
1277
|
-
exports.latestIdentifiesRequestSchema = latestIdentifiesRequestSchema;
|
|
1278
|
-
exports.latestIdentifiesResponseSchema = latestIdentifiesResponseSchema;
|
|
1279
|
-
exports.listUsersParamsSchema = listUsersParamsSchema;
|
|
1280
|
-
exports.reservedPropertiesSchema = reservedPropertiesSchema;
|
|
1281
|
-
exports.serverContextSchema = serverContextSchema;
|
|
1282
|
-
exports.tbAny = tbAny;
|
|
1283
834
|
exports.timezones = timezones;
|
|
1284
|
-
exports.tinyBirdBaseSchema = tinyBirdBaseSchema;
|
|
1285
|
-
exports.topActionsResponseSchema = topActionsResponseSchema;
|
|
1286
|
-
exports.topBrowsersResponseSchema = topBrowsersResponseSchema;
|
|
1287
|
-
exports.topDevicesResponseSchema = topDevicesResponseSchema;
|
|
1288
|
-
exports.topLocationsResponseSchema = topLocationsResponseSchema;
|
|
1289
|
-
exports.topPagesResponseSchema = topPagesResponseSchema;
|
|
1290
|
-
exports.topSourcesResponseSchema = topSourcesResponseSchema;
|
|
1291
|
-
exports.topSourcesSchema = topSourcesSchema;
|
|
1292
|
-
exports.trackedEventSchema = trackedEventSchema;
|
|
1293
|
-
exports.trackedEventTypesSchema = trackedEventTypesSchema;
|
|
1294
|
-
exports.userEventsResponseSchema = userEventsResponseSchema;
|