@schematichq/schematic-react 1.2.17 → 1.2.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.
@@ -651,6 +651,36 @@ function v4(options, buf, offset) {
651
651
  }
652
652
  var v4_default = v4;
653
653
  var import_polyfill = __toESM2(require_browser_polyfill());
654
+ function EntitlementValueTypeFromJSON(json) {
655
+ return EntitlementValueTypeFromJSONTyped(json, false);
656
+ }
657
+ function EntitlementValueTypeFromJSONTyped(json, ignoreDiscriminator) {
658
+ return json;
659
+ }
660
+ function FeatureEntitlementFromJSON(json) {
661
+ return FeatureEntitlementFromJSONTyped(json, false);
662
+ }
663
+ function FeatureEntitlementFromJSONTyped(json, ignoreDiscriminator) {
664
+ if (json == null) {
665
+ return json;
666
+ }
667
+ return {
668
+ allocation: json["allocation"] == null ? void 0 : json["allocation"],
669
+ creditId: json["credit_id"] == null ? void 0 : json["credit_id"],
670
+ creditRemaining: json["credit_remaining"] == null ? void 0 : json["credit_remaining"],
671
+ creditTotal: json["credit_total"] == null ? void 0 : json["credit_total"],
672
+ creditUsed: json["credit_used"] == null ? void 0 : json["credit_used"],
673
+ eventName: json["event_name"] == null ? void 0 : json["event_name"],
674
+ featureId: json["feature_id"],
675
+ featureKey: json["feature_key"],
676
+ metricPeriod: json["metric_period"] == null ? void 0 : json["metric_period"],
677
+ metricResetAt: json["metric_reset_at"] == null ? void 0 : new Date(json["metric_reset_at"]),
678
+ monthReset: json["month_reset"] == null ? void 0 : json["month_reset"],
679
+ softLimit: json["soft_limit"] == null ? void 0 : json["soft_limit"],
680
+ usage: json["usage"] == null ? void 0 : json["usage"],
681
+ valueType: EntitlementValueTypeFromJSON(json["value_type"])
682
+ };
683
+ }
654
684
  function CheckFlagResponseDataFromJSON(json) {
655
685
  return CheckFlagResponseDataFromJSONTyped(json, false);
656
686
  }
@@ -660,6 +690,7 @@ function CheckFlagResponseDataFromJSONTyped(json, ignoreDiscriminator) {
660
690
  }
661
691
  return {
662
692
  companyId: json["company_id"] == null ? void 0 : json["company_id"],
693
+ entitlement: json["entitlement"] == null ? void 0 : FeatureEntitlementFromJSON(json["entitlement"]),
663
694
  error: json["error"] == null ? void 0 : json["error"],
664
695
  featureAllocation: json["feature_allocation"] == null ? void 0 : json["feature_allocation"],
665
696
  featureUsage: json["feature_usage"] == null ? void 0 : json["feature_usage"],
@@ -799,7 +830,7 @@ function contextString(context) {
799
830
  }, {});
800
831
  return JSON.stringify(sortedContext);
801
832
  }
802
- var version = "1.2.17";
833
+ var version = "1.2.21";
803
834
  var anonymousIdKey = "schematicId";
804
835
  var Schematic = class {
805
836
  additionalHeaders = {};
@@ -845,6 +876,7 @@ var Schematic = class {
845
876
  retryTimer = null;
846
877
  flagValueDefaults = {};
847
878
  flagCheckDefaults = {};
879
+ fallbackCheckCache = {};
848
880
  constructor(apiKey, options) {
849
881
  this.apiKey = apiKey;
850
882
  this.eventQueue = [];
@@ -1104,6 +1136,13 @@ var Schematic = class {
1104
1136
  );
1105
1137
  if (typeof flagCheck !== "undefined") {
1106
1138
  this.submitFlagCheckEvent(key, flagCheck, context);
1139
+ } else {
1140
+ const fallbackResult = this.resolveFallbackCheckFlagReturn(
1141
+ key,
1142
+ fallback,
1143
+ "No flag values available"
1144
+ );
1145
+ this.submitFlagCheckEvent(key, fallbackResult, context);
1107
1146
  }
1108
1147
  return result;
1109
1148
  } catch (error) {
@@ -1269,6 +1308,9 @@ var Schematic = class {
1269
1308
  this.setIsPending(false);
1270
1309
  return Promise.resolve();
1271
1310
  }
1311
+ if (contextString(context) === contextString(this.context) && this.conn !== null && !this.isPending) {
1312
+ return;
1313
+ }
1272
1314
  try {
1273
1315
  this.setIsPending(true);
1274
1316
  if (!this.conn) {
@@ -1308,7 +1350,10 @@ var Schematic = class {
1308
1350
  await this.wsSendMessage(socket, context);
1309
1351
  } catch (error) {
1310
1352
  console.warn("Failed to establish WebSocket connection:", error);
1311
- throw error;
1353
+ this.context = context;
1354
+ this.flushContextDependentEventQueue();
1355
+ this.setIsPending(false);
1356
+ this.attemptReconnect();
1312
1357
  }
1313
1358
  };
1314
1359
  /**
@@ -2049,6 +2094,7 @@ var Schematic = class {
2049
2094
  };
2050
2095
  };
2051
2096
  setIsPending = (isPending) => {
2097
+ if (this.isPending === isPending) return;
2052
2098
  this.isPending = isPending;
2053
2099
  this.isPendingListeners.forEach(
2054
2100
  (listener) => notifyPendingListener(listener, isPending)
@@ -2063,11 +2109,14 @@ var Schematic = class {
2063
2109
  return check;
2064
2110
  }
2065
2111
  if (flagKey in this.flagCheckDefaults || flagKey in this.flagValueDefaults) {
2066
- return this.resolveFallbackCheckFlagReturn(
2067
- flagKey,
2068
- void 0,
2069
- "Default value used"
2070
- );
2112
+ if (!(flagKey in this.fallbackCheckCache)) {
2113
+ this.fallbackCheckCache[flagKey] = this.resolveFallbackCheckFlagReturn(
2114
+ flagKey,
2115
+ void 0,
2116
+ "Default value used"
2117
+ );
2118
+ }
2119
+ return this.fallbackCheckCache[flagKey];
2071
2120
  }
2072
2121
  return void 0;
2073
2122
  };
@@ -2179,7 +2228,7 @@ var notifyFlagValueListener = (listener, value) => {
2179
2228
  var import_react = __toESM(require("react"));
2180
2229
 
2181
2230
  // src/version.ts
2182
- var version2 = "1.2.17";
2231
+ var version2 = "1.2.21";
2183
2232
 
2184
2233
  // src/context/schematic.tsx
2185
2234
  var import_jsx_runtime = require("react/jsx-runtime");
@@ -606,6 +606,36 @@ function v4(options, buf, offset) {
606
606
  }
607
607
  var v4_default = v4;
608
608
  var import_polyfill = __toESM(require_browser_polyfill());
609
+ function EntitlementValueTypeFromJSON(json) {
610
+ return EntitlementValueTypeFromJSONTyped(json, false);
611
+ }
612
+ function EntitlementValueTypeFromJSONTyped(json, ignoreDiscriminator) {
613
+ return json;
614
+ }
615
+ function FeatureEntitlementFromJSON(json) {
616
+ return FeatureEntitlementFromJSONTyped(json, false);
617
+ }
618
+ function FeatureEntitlementFromJSONTyped(json, ignoreDiscriminator) {
619
+ if (json == null) {
620
+ return json;
621
+ }
622
+ return {
623
+ allocation: json["allocation"] == null ? void 0 : json["allocation"],
624
+ creditId: json["credit_id"] == null ? void 0 : json["credit_id"],
625
+ creditRemaining: json["credit_remaining"] == null ? void 0 : json["credit_remaining"],
626
+ creditTotal: json["credit_total"] == null ? void 0 : json["credit_total"],
627
+ creditUsed: json["credit_used"] == null ? void 0 : json["credit_used"],
628
+ eventName: json["event_name"] == null ? void 0 : json["event_name"],
629
+ featureId: json["feature_id"],
630
+ featureKey: json["feature_key"],
631
+ metricPeriod: json["metric_period"] == null ? void 0 : json["metric_period"],
632
+ metricResetAt: json["metric_reset_at"] == null ? void 0 : new Date(json["metric_reset_at"]),
633
+ monthReset: json["month_reset"] == null ? void 0 : json["month_reset"],
634
+ softLimit: json["soft_limit"] == null ? void 0 : json["soft_limit"],
635
+ usage: json["usage"] == null ? void 0 : json["usage"],
636
+ valueType: EntitlementValueTypeFromJSON(json["value_type"])
637
+ };
638
+ }
609
639
  function CheckFlagResponseDataFromJSON(json) {
610
640
  return CheckFlagResponseDataFromJSONTyped(json, false);
611
641
  }
@@ -615,6 +645,7 @@ function CheckFlagResponseDataFromJSONTyped(json, ignoreDiscriminator) {
615
645
  }
616
646
  return {
617
647
  companyId: json["company_id"] == null ? void 0 : json["company_id"],
648
+ entitlement: json["entitlement"] == null ? void 0 : FeatureEntitlementFromJSON(json["entitlement"]),
618
649
  error: json["error"] == null ? void 0 : json["error"],
619
650
  featureAllocation: json["feature_allocation"] == null ? void 0 : json["feature_allocation"],
620
651
  featureUsage: json["feature_usage"] == null ? void 0 : json["feature_usage"],
@@ -754,7 +785,7 @@ function contextString(context) {
754
785
  }, {});
755
786
  return JSON.stringify(sortedContext);
756
787
  }
757
- var version = "1.2.17";
788
+ var version = "1.2.21";
758
789
  var anonymousIdKey = "schematicId";
759
790
  var Schematic = class {
760
791
  additionalHeaders = {};
@@ -800,6 +831,7 @@ var Schematic = class {
800
831
  retryTimer = null;
801
832
  flagValueDefaults = {};
802
833
  flagCheckDefaults = {};
834
+ fallbackCheckCache = {};
803
835
  constructor(apiKey, options) {
804
836
  this.apiKey = apiKey;
805
837
  this.eventQueue = [];
@@ -1059,6 +1091,13 @@ var Schematic = class {
1059
1091
  );
1060
1092
  if (typeof flagCheck !== "undefined") {
1061
1093
  this.submitFlagCheckEvent(key, flagCheck, context);
1094
+ } else {
1095
+ const fallbackResult = this.resolveFallbackCheckFlagReturn(
1096
+ key,
1097
+ fallback,
1098
+ "No flag values available"
1099
+ );
1100
+ this.submitFlagCheckEvent(key, fallbackResult, context);
1062
1101
  }
1063
1102
  return result;
1064
1103
  } catch (error) {
@@ -1224,6 +1263,9 @@ var Schematic = class {
1224
1263
  this.setIsPending(false);
1225
1264
  return Promise.resolve();
1226
1265
  }
1266
+ if (contextString(context) === contextString(this.context) && this.conn !== null && !this.isPending) {
1267
+ return;
1268
+ }
1227
1269
  try {
1228
1270
  this.setIsPending(true);
1229
1271
  if (!this.conn) {
@@ -1263,7 +1305,10 @@ var Schematic = class {
1263
1305
  await this.wsSendMessage(socket, context);
1264
1306
  } catch (error) {
1265
1307
  console.warn("Failed to establish WebSocket connection:", error);
1266
- throw error;
1308
+ this.context = context;
1309
+ this.flushContextDependentEventQueue();
1310
+ this.setIsPending(false);
1311
+ this.attemptReconnect();
1267
1312
  }
1268
1313
  };
1269
1314
  /**
@@ -2004,6 +2049,7 @@ var Schematic = class {
2004
2049
  };
2005
2050
  };
2006
2051
  setIsPending = (isPending) => {
2052
+ if (this.isPending === isPending) return;
2007
2053
  this.isPending = isPending;
2008
2054
  this.isPendingListeners.forEach(
2009
2055
  (listener) => notifyPendingListener(listener, isPending)
@@ -2018,11 +2064,14 @@ var Schematic = class {
2018
2064
  return check;
2019
2065
  }
2020
2066
  if (flagKey in this.flagCheckDefaults || flagKey in this.flagValueDefaults) {
2021
- return this.resolveFallbackCheckFlagReturn(
2022
- flagKey,
2023
- void 0,
2024
- "Default value used"
2025
- );
2067
+ if (!(flagKey in this.fallbackCheckCache)) {
2068
+ this.fallbackCheckCache[flagKey] = this.resolveFallbackCheckFlagReturn(
2069
+ flagKey,
2070
+ void 0,
2071
+ "Default value used"
2072
+ );
2073
+ }
2074
+ return this.fallbackCheckCache[flagKey];
2026
2075
  }
2027
2076
  return void 0;
2028
2077
  };
@@ -2134,7 +2183,7 @@ var notifyFlagValueListener = (listener, value) => {
2134
2183
  import React, { createContext, useEffect, useMemo, useRef } from "react";
2135
2184
 
2136
2185
  // src/version.ts
2137
- var version2 = "1.2.17";
2186
+ var version2 = "1.2.21";
2138
2187
 
2139
2188
  // src/context/schematic.tsx
2140
2189
  import { jsx } from "react/jsx-runtime";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@schematichq/schematic-react",
3
- "version": "1.2.17",
3
+ "version": "1.2.21",
4
4
  "main": "dist/schematic-react.cjs.js",
5
5
  "module": "dist/schematic-react.esm.js",
6
6
  "types": "dist/schematic-react.d.ts",
@@ -31,30 +31,30 @@
31
31
  "prepare": "husky"
32
32
  },
33
33
  "dependencies": {
34
- "@schematichq/schematic-js": "^1.2.17"
34
+ "@schematichq/schematic-js": "^1.2.21"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@eslint/js": "^10.0.1",
38
- "@microsoft/api-extractor": "^7.56.3",
38
+ "@microsoft/api-extractor": "^7.57.6",
39
39
  "@testing-library/dom": "^10.4.1",
40
40
  "@testing-library/jest-dom": "^6.9.1",
41
41
  "@testing-library/react": "^16.3.2",
42
42
  "@types/react": "^19.2.14",
43
43
  "@vitest/browser": "^4.0.18",
44
44
  "esbuild": "^0.27.3",
45
- "eslint": "^9.39.2",
45
+ "eslint": "^10.0.2",
46
46
  "eslint-plugin-import": "^2.32.0",
47
47
  "eslint-plugin-react": "^7.37.5",
48
48
  "eslint-plugin-react-hooks": "^7.0.1",
49
- "globals": "^17.3.0",
50
- "happy-dom": "^20.6.1",
49
+ "globals": "^17.4.0",
50
+ "happy-dom": "^20.8.3",
51
51
  "husky": "^9.1.7",
52
- "jsdom": "^28.0.0",
52
+ "jsdom": "^28.1.0",
53
53
  "prettier": "^3.8.1",
54
54
  "react": "^19.2.4",
55
55
  "react-dom": "^19.2.4",
56
56
  "typescript": "^5.9.3",
57
- "typescript-eslint": "^8.55.0",
57
+ "typescript-eslint": "^8.56.1",
58
58
  "vitest": "^4.0.18"
59
59
  },
60
60
  "peerDependencies": {