@opexa/portal-sdk 0.58.0 → 0.58.1

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/dist/index.cjs CHANGED
@@ -6144,6 +6144,7 @@ function subMinutes(date, minutes) {
6144
6144
 
6145
6145
  // src/sdk/ad-manager.ts
6146
6146
  var AD_CLICK_ID_STORAGE_KEY = "sdk/ad-click-id";
6147
+ var FBP_STORAGE_KEY = "sdk/fbp";
6147
6148
  var AdManager = class {
6148
6149
  logger;
6149
6150
  constructor(config) {
@@ -6188,6 +6189,45 @@ var AdManager = class {
6188
6189
  return null;
6189
6190
  }
6190
6191
  }
6192
+ set fbp(value) {
6193
+ if (this.isServer) {
6194
+ this.logger.warn("'localStorage' is not available on the server.");
6195
+ return;
6196
+ }
6197
+ if (value === null) {
6198
+ localStorage.removeItem(FBP_STORAGE_KEY);
6199
+ return;
6200
+ }
6201
+ const n = /* @__PURE__ */ new Date();
6202
+ const o = JSON.stringify({
6203
+ value,
6204
+ expiresAt: subMinutes(addDays(n, 90), 2).getTime()
6205
+ });
6206
+ localStorage.setItem(FBP_STORAGE_KEY, o);
6207
+ }
6208
+ get fbp() {
6209
+ if (this.isServer) {
6210
+ this.logger.warn("'localStorage' is not available on the server.");
6211
+ return null;
6212
+ }
6213
+ const v = localStorage.getItem(FBP_STORAGE_KEY);
6214
+ if (!v) return null;
6215
+ try {
6216
+ const o = JSON.parse(v);
6217
+ if (!o.value) return null;
6218
+ if (!o.expiresAt) return null;
6219
+ const d = new Date(o.expiresAt);
6220
+ const n = /* @__PURE__ */ new Date();
6221
+ if (isAfter(n, d)) {
6222
+ localStorage.removeItem(FBP_STORAGE_KEY);
6223
+ return null;
6224
+ }
6225
+ return o.value;
6226
+ } catch {
6227
+ localStorage.removeItem(FBP_STORAGE_KEY);
6228
+ return null;
6229
+ }
6230
+ }
6191
6231
  get isServer() {
6192
6232
  return typeof window === "undefined";
6193
6233
  }
@@ -6250,6 +6290,15 @@ async function getFingerprint() {
6250
6290
  return null;
6251
6291
  }
6252
6292
  }
6293
+ function getCookie(name) {
6294
+ if (typeof document === "undefined") return null;
6295
+ const nameLenPlus = name.length + 1;
6296
+ return document.cookie.split(";").map((c) => c.trim()).filter((cookie) => {
6297
+ return cookie.substring(0, nameLenPlus) === `${name}=`;
6298
+ }).map((cookie) => {
6299
+ return decodeURIComponent(cookie.substring(nameLenPlus));
6300
+ })[0] || null;
6301
+ }
6253
6302
 
6254
6303
  // src/sdk/cellexpert-manager.ts
6255
6304
  var CXD_STORAGE_KEY = "sdk/cxd";
@@ -8013,7 +8062,8 @@ var Transformer = class {
8013
8062
  agent: data.agent ?? null,
8014
8063
  level: data.level ?? 0,
8015
8064
  dateTimeLastActive: data.dateTimeLastActive ? new Date(data.dateTimeLastActive) : void 0,
8016
- partition: data.partition
8065
+ partition: data.partition,
8066
+ gigRewardsQuestDetails: data.gigRewardsQuestDetails ?? void 0
8017
8067
  };
8018
8068
  return compact(o);
8019
8069
  }
@@ -8874,6 +8924,7 @@ var Sdk = class {
8874
8924
  sitePlatform,
8875
8925
  logs
8876
8926
  };
8927
+ this.collectMetaDetails();
8877
8928
  }
8878
8929
  _fetch = null;
8879
8930
  _middleware;
@@ -8955,6 +9006,12 @@ var Sdk = class {
8955
9006
  get adClickId() {
8956
9007
  return this.adManager.clickId;
8957
9008
  }
9009
+ set fbp(value) {
9010
+ this.adManager.fbp = value;
9011
+ }
9012
+ get fbp() {
9013
+ return this.adManager.fbp;
9014
+ }
8958
9015
  /*
8959
9016
  *=============================================
8960
9017
  * CXD
@@ -9023,18 +9080,30 @@ var Sdk = class {
9023
9080
  async fingerprint() {
9024
9081
  return await getFingerprint();
9025
9082
  }
9026
- /*
9027
- *=============================================
9028
- * MISCELLANEOUS MIDDLEWARE
9029
- *=============================================
9030
- */
9031
9083
  get miscMiddleware() {
9032
9084
  return async (request) => {
9033
9085
  const adClickId = this.adManager.clickId;
9034
9086
  if (adClickId) request.headers.set("Ad-Click-Id", adClickId);
9087
+ const fbp = this.adManager.fbp;
9088
+ if (fbp) request.headers.set("fbp", fbp);
9035
9089
  return request;
9036
9090
  };
9037
9091
  }
9092
+ collectMetaDetails() {
9093
+ if (typeof window === "undefined") return;
9094
+ const searchParams = new URLSearchParams(window.location.search);
9095
+ const fbclid = searchParams.get("fbclid");
9096
+ const fbc = getCookie("_fbc");
9097
+ const fbp = getCookie("_fbp");
9098
+ if (fbclid) {
9099
+ this.adClickId = fbclid;
9100
+ } else if (fbc) {
9101
+ this.adClickId = fbc.includes(".") ? fbc.split(".").pop() || fbc : fbc;
9102
+ }
9103
+ if (fbp) {
9104
+ this.fbp = fbp;
9105
+ }
9106
+ }
9038
9107
  async signIn(input) {
9039
9108
  if (input.type === "TOKEN") {
9040
9109
  console.warn(