@reservamos/browser-analytics 0.3.1-alpha.7 → 1.0.0

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.
@@ -309,6 +309,9 @@ declare const paymentAttemptSchema: z.ZodObject<{
309
309
  "Passenger Document Type": string;
310
310
  "Passenger Document Id": string;
311
311
  }>, "many">>;
312
+ Insurance: z.ZodOptional<z.ZodBoolean>;
313
+ Coupon: z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
314
+ "User Status": z.ZodOptional<z.ZodEffects<z.ZodString, string, string>>;
312
315
  }, "strict", z.ZodTypeAny, {
313
316
  product: "web" | "web-mobile" | "ios" | "android" | "app";
314
317
  Trips: {
@@ -351,6 +354,9 @@ declare const paymentAttemptSchema: z.ZodObject<{
351
354
  "Passenger Document Id": string;
352
355
  }[] | undefined;
353
356
  "Operation Id"?: string | undefined;
357
+ Insurance?: boolean | undefined;
358
+ Coupon?: string | undefined;
359
+ "User Status"?: string | undefined;
354
360
  }, {
355
361
  product: "web" | "web-mobile" | "ios" | "android" | "app";
356
362
  Trips: {
@@ -393,6 +399,9 @@ declare const paymentAttemptSchema: z.ZodObject<{
393
399
  "Passenger Document Id": string;
394
400
  }[] | undefined;
395
401
  "Operation Id"?: string | undefined;
402
+ Insurance?: boolean | undefined;
403
+ Coupon?: string | undefined;
404
+ "User Status"?: string | undefined;
396
405
  }>;
397
406
  export type PaymentAttemptProps = z.infer<typeof paymentAttemptSchema>;
398
407
  declare const pickedDepartureSchema: z.ZodObject<{
@@ -941,21 +950,39 @@ declare function trackViewResults(eventData: ViewResultsProps, meta?: EventMetad
941
950
  declare const CreateAnonymousProfileSchema: z.ZodEffects<z.ZodObject<{
942
951
  email: z.ZodOptional<z.ZodString>;
943
952
  phone: z.ZodOptional<z.ZodString>;
953
+ cpf: z.ZodOptional<z.ZodString>;
954
+ passport: z.ZodOptional<z.ZodString>;
955
+ rg: z.ZodOptional<z.ZodString>;
944
956
  }, "strip", z.ZodTypeAny, {
945
957
  email?: string | undefined;
946
958
  phone?: string | undefined;
959
+ cpf?: string | undefined;
960
+ passport?: string | undefined;
961
+ rg?: string | undefined;
947
962
  }, {
948
963
  email?: string | undefined;
949
964
  phone?: string | undefined;
965
+ cpf?: string | undefined;
966
+ passport?: string | undefined;
967
+ rg?: string | undefined;
950
968
  }>, {
951
969
  email?: string | undefined;
952
970
  phone?: string | undefined;
971
+ cpf?: string | undefined;
972
+ passport?: string | undefined;
973
+ rg?: string | undefined;
953
974
  }, {
954
975
  email?: string | undefined;
955
976
  phone?: string | undefined;
977
+ cpf?: string | undefined;
978
+ passport?: string | undefined;
979
+ rg?: string | undefined;
956
980
  }>;
957
981
  export type CreateAnonymousProfileProps = z.infer<typeof CreateAnonymousProfileSchema>;
958
- declare function createAnonymousProfile(payload: CreateAnonymousProfileProps): Promise<void>;
982
+ export interface AnonymousProfileResponse {
983
+ id: string;
984
+ }
985
+ declare function createAnonymousProfile(payload: CreateAnonymousProfileProps): Promise<AnonymousProfileResponse | undefined>;
959
986
  declare const IdentifySchema: z.ZodObject<{
960
987
  firstName: z.ZodOptional<z.ZodString>;
961
988
  lastName: z.ZodOptional<z.ZodString>;
@@ -13117,6 +13117,10 @@ const arrayField = (schema, fieldName, minLength) => {
13117
13117
  );
13118
13118
  }
13119
13119
  };
13120
+ const booleanField = (fieldName) => z.boolean({
13121
+ required_error: `${fieldName} is required`,
13122
+ invalid_type_error: `${fieldName} must be a boolean`
13123
+ });
13120
13124
  const interestInSearchSchema = z.object({
13121
13125
  "Origin": stringField("Origin").optional(),
13122
13126
  "Destination": stringField("Destination").optional(),
@@ -13188,7 +13192,10 @@ const paymentAttemptSchema = z.object({
13188
13192
  "Payment Type": z.string().min(1, "Payment Type is required"),
13189
13193
  "Total": numberField("Total"),
13190
13194
  "product": productValidation,
13191
- "Passengers": arrayField(passengerSchema, "Passengers", 1).optional()
13195
+ "Passengers": arrayField(passengerSchema, "Passengers", 1).optional(),
13196
+ "Insurance": booleanField("Insurance").optional(),
13197
+ "Coupon": stringField("Coupon").optional(),
13198
+ "User Status": stringField("User Status").optional()
13192
13199
  }).strict();
13193
13200
  const EVENT_NAME$6 = "Payment Attempt";
13194
13201
  const trackPaymentAttempt = async (eventProps, meta = {}) => {
@@ -15939,27 +15946,36 @@ var jsApiClient = { exports: {} };
15939
15946
  var jsApiClientExports = jsApiClient.exports;
15940
15947
  const CreateAnonymousProfileSchema = z.object({
15941
15948
  email: z.string().email().optional(),
15942
- phone: z.string().optional()
15949
+ phone: z.string().optional(),
15950
+ cpf: z.string().optional(),
15951
+ passport: z.string().optional(),
15952
+ rg: z.string().optional()
15943
15953
  }).refine((data) => data.email || data.phone, {
15944
15954
  message: "At least one of 'email' or 'phone' must be provided"
15945
15955
  });
15946
- function getAnonymousProfilePayload(values) {
15956
+ function getAnonymousProfilePayload(values, identifiersProps) {
15947
15957
  let identifier_key = "phone";
15948
15958
  let identifier_value = values.phone || "";
15949
- const details = {};
15959
+ const identifiers = [];
15950
15960
  if (values.email) {
15951
15961
  identifier_key = "email";
15952
15962
  identifier_value = values.email;
15953
15963
  }
15964
+ const allowedKeys = ["cpf", "passport", "rg", "email", "phone"];
15954
15965
  Object.entries(values).forEach(([key, value]) => {
15955
- if (key !== "email" && key !== identifier_key && value !== void 0) {
15956
- details[key] = value;
15966
+ if (allowedKeys.includes(key.toLowerCase()) && value) {
15967
+ if (key !== identifier_key) {
15968
+ identifiers.push({ key, value });
15969
+ }
15957
15970
  }
15958
15971
  });
15972
+ if (identifiersProps.length) {
15973
+ identifiersProps.forEach((item) => identifiers.push(item));
15974
+ }
15959
15975
  return {
15960
15976
  identifier_key,
15961
15977
  identifier_value,
15962
- details
15978
+ identifiers
15963
15979
  };
15964
15980
  }
15965
15981
  async function createAnonymousProfile(payload) {
@@ -15969,12 +15985,14 @@ async function createAnonymousProfile(payload) {
15969
15985
  const userFingerprintId = fingerprintService.getCachedFingerprint();
15970
15986
  const distinctId = mixpanelService.getMixpanelDistinctId();
15971
15987
  if (userFingerprintId)
15972
- identifiers.push({ key: "fingerprint_id", value: userFingerprintId });
15988
+ identifiers.push({ key: "fingerprint", value: userFingerprintId });
15973
15989
  if (distinctId) identifiers.push({ key: "distinct_id", value: distinctId });
15974
- const dataPayload = getAnonymousProfilePayload(payload);
15975
- await jsApiClientExports.core.createAnonymousProfile({ ...dataPayload, identifiers });
15990
+ const dataPayload = getAnonymousProfilePayload(payload, identifiers);
15991
+ const result = await jsApiClientExports.core.createAnonymousProfile(dataPayload);
15992
+ return result.data;
15976
15993
  } catch (error) {
15977
15994
  console.error("Could not create anonymous profile:", error);
15995
+ return void 0;
15978
15996
  }
15979
15997
  }
15980
15998
  const KNOWN_PROPERTIES = ["firstName", "lastName", "email", "phone"];
@@ -16008,6 +16026,10 @@ async function identify(userId, properties = {}) {
16008
16026
  console.error("User ID is required for identification.");
16009
16027
  throw new Error("User ID is required for identification.");
16010
16028
  }
16029
+ const anonymousProfile = await createAnonymousProfile(properties);
16030
+ if (anonymousProfile) {
16031
+ properties.reservamos_one_id = anonymousProfile.id;
16032
+ }
16011
16033
  const mappedProps = mapProperties(properties);
16012
16034
  mixpanelService.identify(userId, mappedProps);
16013
16035
  const fingerprint = await fingerprintService.getFingerprint();
@@ -16016,11 +16038,6 @@ async function identify(userId, properties = {}) {
16016
16038
  }
16017
16039
  } catch (error) {
16018
16040
  console.error("Error identifying user", error);
16019
- } finally {
16020
- createAnonymousProfile({
16021
- email: properties.email,
16022
- phone: properties.phone
16023
- });
16024
16041
  }
16025
16042
  }
16026
16043
  const origin = window.location.origin;
@@ -16033,7 +16050,7 @@ const coreAPIConfig = {
16033
16050
  }
16034
16051
  },
16035
16052
  prod: {
16036
- coreUrl: "https://datalake-api-dev.reservamossaas.com/api",
16053
+ coreUrl: "https://data-lake.reservamossaas.com/api",
16037
16054
  coreVersion: "v1",
16038
16055
  headers: {
16039
16056
  Origin: origin