@opexa/portal-sdk 0.59.138 → 0.59.141

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
@@ -4931,9 +4931,110 @@ function callIfFn(value, ...args) {
4931
4931
  return value;
4932
4932
  }
4933
4933
  }
4934
+
4935
+ // src/utils/capture-fingerprint-preference.ts
4936
+ function captureFingerprintPreference(search) {
4937
+ if (typeof window === "undefined") return;
4938
+ const preference = new URLSearchParams(window.location.search).get(
4939
+ "useFingerPrint"
4940
+ );
4941
+ if (preference === "true") {
4942
+ sessionStorage.setItem("useFingerPrint", "true");
4943
+ } else if (preference === "false") {
4944
+ sessionStorage.removeItem("useFingerPrint");
4945
+ }
4946
+ }
4934
4947
  var thumbmark_instance;
4948
+ var opexaFingerprintPromise;
4949
+ function isNonemptyString(value) {
4950
+ return typeof value === "string" && value.trim().length > 0;
4951
+ }
4952
+ async function generateOpexaFingerprint() {
4953
+ try {
4954
+ const {
4955
+ generateHardwareSignal,
4956
+ generateSystemSignal,
4957
+ generatePluginSignal,
4958
+ generateWebglSignal,
4959
+ generateCanvasSignal
4960
+ } = await import('@opexa/fingerprint');
4961
+ const signals = await Promise.all([
4962
+ generateHardwareSignal(),
4963
+ generateSystemSignal(),
4964
+ generatePluginSignal(),
4965
+ generateWebglSignal(),
4966
+ generateCanvasSignal()
4967
+ ]);
4968
+ if (!signals.every(isNonemptyString)) {
4969
+ throw new Error("Fingerprint generation returned an invalid signal");
4970
+ }
4971
+ const [hardware, system, plugin, webgl, canvas] = signals;
4972
+ const query = new URLSearchParams({
4973
+ hardware,
4974
+ system,
4975
+ plugin,
4976
+ webgl,
4977
+ canvas
4978
+ });
4979
+ const controller = new AbortController();
4980
+ let timeout;
4981
+ try {
4982
+ const request = async () => {
4983
+ const response = await fetch(
4984
+ `https://fingerprint.atalos.io/fingerprint?${query}`,
4985
+ { cache: "no-store", signal: controller.signal }
4986
+ );
4987
+ if (!response.ok) {
4988
+ throw new Error(`Fingerprint request failed: ${response.status}`);
4989
+ }
4990
+ const payload = await response.json();
4991
+ if (!payload || typeof payload !== "object" || !("id" in payload) || !isNonemptyString(payload.id)) {
4992
+ throw new Error("Fingerprint response did not contain a valid id");
4993
+ }
4994
+ return payload.id;
4995
+ };
4996
+ const id = await Promise.race([
4997
+ request(),
4998
+ new Promise((_, reject) => {
4999
+ timeout = setTimeout(() => {
5000
+ reject(new Error("Fingerprint request timed out"));
5001
+ controller.abort();
5002
+ }, 3e4);
5003
+ })
5004
+ ]);
5005
+ try {
5006
+ sessionStorage.setItem("opexaFingerprint", id);
5007
+ } catch {
5008
+ }
5009
+ return id;
5010
+ } finally {
5011
+ clearTimeout(timeout);
5012
+ }
5013
+ } catch (error) {
5014
+ throw error instanceof Error ? error : new Error("Fingerprint generation failed");
5015
+ }
5016
+ }
4935
5017
  async function getFingerPrint() {
4936
5018
  if (typeof window === "undefined") return null;
5019
+ let useOpexaFingerprint;
5020
+ try {
5021
+ useOpexaFingerprint = sessionStorage.getItem("useFingerPrint") === "true";
5022
+ } catch {
5023
+ return null;
5024
+ }
5025
+ if (useOpexaFingerprint) {
5026
+ try {
5027
+ const cached = sessionStorage.getItem("opexaFingerprint");
5028
+ if (isNonemptyString(cached)) return cached;
5029
+ } catch {
5030
+ }
5031
+ if (!opexaFingerprintPromise) {
5032
+ opexaFingerprintPromise = generateOpexaFingerprint().finally(() => {
5033
+ opexaFingerprintPromise = void 0;
5034
+ });
5035
+ }
5036
+ return await opexaFingerprintPromise;
5037
+ }
4937
5038
  if (!thumbmark_instance) {
4938
5039
  thumbmark_instance = new thumbmarkjs.Thumbmark({
4939
5040
  logging: false,
@@ -5024,6 +5125,7 @@ var AuthService = class {
5024
5125
  async createSession(input, version = 1) {
5025
5126
  const headers = new Headers(this.headers);
5026
5127
  if (version === 3 || version === 4) {
5128
+ captureFingerprintPreference();
5027
5129
  const fingerprint = await getFingerPrint();
5028
5130
  if (fingerprint) {
5029
5131
  headers.append("Fingerprint", fingerprint);
@@ -5166,13 +5268,14 @@ var AuthService = class {
5166
5268
  if (version !== 4 || refreshToken) {
5167
5269
  headers.append("Authorization", `Bearer ${refreshToken}`);
5168
5270
  }
5169
- try {
5170
- if (version === 3 || version === 4) {
5171
- const fingerprint = await getFingerPrint();
5172
- if (fingerprint) {
5173
- headers.append("Fingerprint", fingerprint);
5174
- }
5271
+ if (version === 3 || version === 4) {
5272
+ captureFingerprintPreference();
5273
+ const fingerprint = await getFingerPrint();
5274
+ if (fingerprint) {
5275
+ headers.append("Fingerprint", fingerprint);
5175
5276
  }
5277
+ }
5278
+ try {
5176
5279
  const isWeb = isWebPlatform();
5177
5280
  const queryParam = isWeb && version === 4 ? "?type=web" : "";
5178
5281
  const res = await fetch(
@@ -5230,6 +5333,7 @@ var AuthService = class {
5230
5333
  const headers = new Headers(this.headers);
5231
5334
  headers.append("Authorization", `Bearer ${accessToken}`);
5232
5335
  if (version === 3 || version === 4) {
5336
+ captureFingerprintPreference();
5233
5337
  const fingerprint = await getFingerPrint();
5234
5338
  if (fingerprint) {
5235
5339
  headers.append("Fingerprint", fingerprint);
@@ -11108,6 +11212,7 @@ var Sdk = class {
11108
11212
  */
11109
11213
  memberDomain = null;
11110
11214
  constructor(config) {
11215
+ captureFingerprintPreference();
11111
11216
  const {
11112
11217
  /**/
11113
11218
  site,
@@ -11421,6 +11526,7 @@ var Sdk = class {
11421
11526
  */
11422
11527
  get authMiddleware() {
11423
11528
  return async (request) => {
11529
+ captureFingerprintPreference();
11424
11530
  this.logger.info("Checking for session");
11425
11531
  const res = await this.sessionManager.get();
11426
11532
  if (res.data) {
@@ -11440,6 +11546,7 @@ var Sdk = class {
11440
11546
  */
11441
11547
  get fingerprintMiddleware() {
11442
11548
  return async (request) => {
11549
+ captureFingerprintPreference();
11443
11550
  const fingerprint = await this.fingerprint();
11444
11551
  if (fingerprint && !request.headers.has("Fingerprint")) {
11445
11552
  request.headers.set("Fingerprint", fingerprint);