@opexa/portal-sdk 0.59.137 → 0.59.140

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.
@@ -4911,9 +4911,110 @@ function callIfFn(value, ...args) {
4911
4911
  return value;
4912
4912
  }
4913
4913
  }
4914
+
4915
+ // src/utils/capture-fingerprint-preference.ts
4916
+ function captureFingerprintPreference(search) {
4917
+ if (typeof window === "undefined") return;
4918
+ const preference = new URLSearchParams(window.location.search).get(
4919
+ "useFingerPrint"
4920
+ );
4921
+ if (preference === "true") {
4922
+ sessionStorage.setItem("useFingerPrint", "true");
4923
+ } else if (preference === "false") {
4924
+ sessionStorage.removeItem("useFingerPrint");
4925
+ }
4926
+ }
4914
4927
  var thumbmark_instance;
4928
+ var opexaFingerprintPromise;
4929
+ function isNonemptyString(value) {
4930
+ return typeof value === "string" && value.trim().length > 0;
4931
+ }
4932
+ async function generateOpexaFingerprint() {
4933
+ try {
4934
+ const {
4935
+ generateHardwareSignal,
4936
+ generateSystemSignal,
4937
+ generatePluginSignal,
4938
+ generateWebglSignal,
4939
+ generateCanvasSignal
4940
+ } = await import('@opexa/fingerprint');
4941
+ const signals = await Promise.all([
4942
+ generateHardwareSignal(),
4943
+ generateSystemSignal(),
4944
+ generatePluginSignal(),
4945
+ generateWebglSignal(),
4946
+ generateCanvasSignal()
4947
+ ]);
4948
+ if (!signals.every(isNonemptyString)) {
4949
+ throw new Error("Fingerprint generation returned an invalid signal");
4950
+ }
4951
+ const [hardware, system, plugin, webgl, canvas] = signals;
4952
+ const query = new URLSearchParams({
4953
+ hardware,
4954
+ system,
4955
+ plugin,
4956
+ webgl,
4957
+ canvas
4958
+ });
4959
+ const controller = new AbortController();
4960
+ let timeout;
4961
+ try {
4962
+ const request = async () => {
4963
+ const response = await fetch(
4964
+ `https://fingerprint.atalos.io/fingerprint?${query}`,
4965
+ { cache: "no-store", signal: controller.signal }
4966
+ );
4967
+ if (!response.ok) {
4968
+ throw new Error(`Fingerprint request failed: ${response.status}`);
4969
+ }
4970
+ const payload = await response.json();
4971
+ if (!payload || typeof payload !== "object" || !("id" in payload) || !isNonemptyString(payload.id)) {
4972
+ throw new Error("Fingerprint response did not contain a valid id");
4973
+ }
4974
+ return payload.id;
4975
+ };
4976
+ const id = await Promise.race([
4977
+ request(),
4978
+ new Promise((_, reject) => {
4979
+ timeout = setTimeout(() => {
4980
+ reject(new Error("Fingerprint request timed out"));
4981
+ controller.abort();
4982
+ }, 3e4);
4983
+ })
4984
+ ]);
4985
+ try {
4986
+ sessionStorage.setItem("opexaFingerprint", id);
4987
+ } catch {
4988
+ }
4989
+ return id;
4990
+ } finally {
4991
+ clearTimeout(timeout);
4992
+ }
4993
+ } catch (error) {
4994
+ throw error instanceof Error ? error : new Error("Fingerprint generation failed");
4995
+ }
4996
+ }
4915
4997
  async function getFingerPrint() {
4916
4998
  if (typeof window === "undefined") return null;
4999
+ let useOpexaFingerprint;
5000
+ try {
5001
+ useOpexaFingerprint = sessionStorage.getItem("useFingerPrint") === "true";
5002
+ } catch {
5003
+ return null;
5004
+ }
5005
+ if (useOpexaFingerprint) {
5006
+ try {
5007
+ const cached = sessionStorage.getItem("opexaFingerprint");
5008
+ if (isNonemptyString(cached)) return cached;
5009
+ } catch {
5010
+ }
5011
+ if (!opexaFingerprintPromise) {
5012
+ opexaFingerprintPromise = generateOpexaFingerprint().finally(() => {
5013
+ opexaFingerprintPromise = void 0;
5014
+ });
5015
+ }
5016
+ return await opexaFingerprintPromise;
5017
+ }
4917
5018
  if (!thumbmark_instance) {
4918
5019
  thumbmark_instance = new thumbmarkjs.Thumbmark({
4919
5020
  logging: false,
@@ -4997,6 +5098,7 @@ var AuthService = class {
4997
5098
  async createSession(input, version = 1) {
4998
5099
  const headers = new Headers(this.headers);
4999
5100
  if (version === 3 || version === 4) {
5101
+ captureFingerprintPreference();
5000
5102
  const fingerprint = await getFingerPrint();
5001
5103
  if (fingerprint) {
5002
5104
  headers.append("Fingerprint", fingerprint);
@@ -5139,13 +5241,14 @@ var AuthService = class {
5139
5241
  if (version !== 4 || refreshToken) {
5140
5242
  headers.append("Authorization", `Bearer ${refreshToken}`);
5141
5243
  }
5142
- try {
5143
- if (version === 3 || version === 4) {
5144
- const fingerprint = await getFingerPrint();
5145
- if (fingerprint) {
5146
- headers.append("Fingerprint", fingerprint);
5147
- }
5244
+ if (version === 3 || version === 4) {
5245
+ captureFingerprintPreference();
5246
+ const fingerprint = await getFingerPrint();
5247
+ if (fingerprint) {
5248
+ headers.append("Fingerprint", fingerprint);
5148
5249
  }
5250
+ }
5251
+ try {
5149
5252
  const isWeb = isWebPlatform();
5150
5253
  const queryParam = isWeb && version === 4 ? "?type=web" : "";
5151
5254
  const res = await fetch(
@@ -5203,6 +5306,7 @@ var AuthService = class {
5203
5306
  const headers = new Headers(this.headers);
5204
5307
  headers.append("Authorization", `Bearer ${accessToken}`);
5205
5308
  if (version === 3 || version === 4) {
5309
+ captureFingerprintPreference();
5206
5310
  const fingerprint = await getFingerPrint();
5207
5311
  if (fingerprint) {
5208
5312
  headers.append("Fingerprint", fingerprint);