@forgecharts/sdk 1.5.37 → 1.5.38

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.
@@ -11040,6 +11040,58 @@ var LicenseManager = class _LicenseManager {
11040
11040
  }
11041
11041
  };
11042
11042
 
11043
+ // src/licensing/packageFeatures.ts
11044
+ var KIT_FEATURE_TO_CAPABILITY = {
11045
+ // charting
11046
+ drawing_tools: "drawingTools",
11047
+ extended_drawing_tools: "extendedDrawings",
11048
+ indicators: "indicators",
11049
+ multi_pane: "multiPane",
11050
+ chart_types: "chartTypes",
11051
+ bar_replay: "barReplay",
11052
+ custom_timeframes: "customTimeframes",
11053
+ overlays: "overlays",
11054
+ // data
11055
+ historical_data: "historicalData",
11056
+ realtime_data: "realtimeData",
11057
+ multiple_providers: "multipleProviders",
11058
+ data_export: "dataExport",
11059
+ continuous_contracts: "continuousContracts",
11060
+ session_hours: "sessionHours",
11061
+ // trading
11062
+ order_entry: "orderEntry",
11063
+ positions_overlay: "positionsOverlay",
11064
+ bracket_orders: "bracketOrders",
11065
+ trailing_stops: "trailingStops",
11066
+ draggable_orders: "draggableOrders",
11067
+ // scripting
11068
+ forgescript: "forgeScript",
11069
+ custom_indicators: "customIndicators",
11070
+ ai_agent: "aiAgent",
11071
+ // workspace
11072
+ saved_layouts: "savedLayouts",
11073
+ multiple_workspaces: "multipleWorkspaces",
11074
+ watchlists: "watchlists",
11075
+ alerts: "alerts",
11076
+ multi_chart_layout: "multiChartLayout"
11077
+ };
11078
+ var PACKAGE_GATED_CAPABILITIES = new Set(
11079
+ Object.values(KIT_FEATURE_TO_CAPABILITY)
11080
+ );
11081
+ function toCapabilityFlags(kitFlags) {
11082
+ const out = {};
11083
+ for (const [kitKey, enabled] of Object.entries(kitFlags)) {
11084
+ const capability = KIT_FEATURE_TO_CAPABILITY[kitKey];
11085
+ if (capability) out[capability] = enabled === true;
11086
+ }
11087
+ return out;
11088
+ }
11089
+ function packageAllows(flags, capability) {
11090
+ if (flags === null) return true;
11091
+ if (!PACKAGE_GATED_CAPABILITIES.has(capability)) return true;
11092
+ return flags[capability] === true;
11093
+ }
11094
+
11043
11095
  // src/licensing/ChartRuntimeResolver.ts
11044
11096
  var ChartRuntimeResolver = class _ChartRuntimeResolver {
11045
11097
  static instance = null;
@@ -11185,6 +11237,7 @@ var ChartRuntimeResolver = class _ChartRuntimeResolver {
11185
11237
  #capabilityWithOverride(name) {
11186
11238
  const ceiling = this.lm.getCapabilities()[name];
11187
11239
  if (!ceiling) return false;
11240
+ if (!packageAllows(this.#userPackageFeatures, name)) return false;
11188
11241
  const explicit = this.lm.getFeatures()[name];
11189
11242
  return explicit === void 0 ? true : explicit === true;
11190
11243
  }
@@ -11410,10 +11463,44 @@ var ChartRuntimeResolver = class _ChartRuntimeResolver {
11410
11463
  */
11411
11464
  #featureOrDefault(name, defaultValue) {
11412
11465
  if (this.lm.isLockedDown()) return false;
11466
+ if (!packageAllows(this.#userPackageFeatures, name)) return false;
11413
11467
  const features = this.lm.getFeatures();
11414
11468
  const flag = features[name];
11415
11469
  return flag === void 0 ? defaultValue : flag === true;
11416
11470
  }
11471
+ // ── Per-user package gating ─────────────────────────────────────────────────
11472
+ /**
11473
+ * Capability flags from the signed-in user's Kit package, or null when none
11474
+ * has been loaded. Null is the default and means "licence only", so every
11475
+ * deployment predating package gating behaves exactly as it did.
11476
+ */
11477
+ #userPackageFeatures = null;
11478
+ /**
11479
+ * Apply the user's Kit package to capability resolution.
11480
+ *
11481
+ * Pass the `features` map from `GET /api/packages/me` verbatim — snake_case
11482
+ * Kit keys are translated here. Pass null to clear (e.g. on sign-out), which
11483
+ * restores licence-only behaviour.
11484
+ *
11485
+ * This can only ever narrow: a package cannot grant a capability the
11486
+ * deployment licence withholds. Both resolvers below consult the licence
11487
+ * regardless of what the package says.
11488
+ */
11489
+ setUserPackageFeatures(kitFlags) {
11490
+ this.#userPackageFeatures = kitFlags === null ? null : toCapabilityFlags(kitFlags);
11491
+ }
11492
+ /** The resolved capability flags from the user's package, for diagnostics. */
11493
+ getUserPackageFeatures() {
11494
+ return this.#userPackageFeatures;
11495
+ }
11496
+ /**
11497
+ * True when a package has been applied. Useful for telling "this user has no
11498
+ * package" apart from "package gating is not in use", which otherwise look
11499
+ * identical from the outside.
11500
+ */
11501
+ hasUserPackage() {
11502
+ return this.#userPackageFeatures !== null;
11503
+ }
11417
11504
  };
11418
11505
  var resolver = () => ChartRuntimeResolver.getInstance();
11419
11506
  var canUseExtendedDrawings = () => resolver().canUseExtendedDrawings();
@@ -18263,6 +18350,52 @@ function useHostLicense(apiUrl, getAuthToken) {
18263
18350
  };
18264
18351
  }, [apiUrl, getAuthToken]);
18265
18352
  }
18353
+ function useUserPackage(apiUrl, getAuthToken) {
18354
+ useEffect(() => {
18355
+ const resolver3 = ChartRuntimeResolver.getInstance();
18356
+ if (!apiUrl || !getAuthToken) {
18357
+ resolver3.setUserPackageFeatures(null);
18358
+ return;
18359
+ }
18360
+ let cancelled = false;
18361
+ void (async () => {
18362
+ try {
18363
+ let token = "";
18364
+ try {
18365
+ token = await getAuthToken();
18366
+ } catch {
18367
+ if (!cancelled) resolver3.setUserPackageFeatures(null);
18368
+ return;
18369
+ }
18370
+ if (cancelled) return;
18371
+ if (!token) {
18372
+ resolver3.setUserPackageFeatures(null);
18373
+ return;
18374
+ }
18375
+ const res = await fetch(`${apiUrl.replace(/\/+$/, "")}/api/packages/me`, {
18376
+ headers: { Authorization: `Bearer ${token}` }
18377
+ });
18378
+ if (cancelled) return;
18379
+ if (!res.ok) {
18380
+ resolver3.setUserPackageFeatures(null);
18381
+ return;
18382
+ }
18383
+ const data = await res.json();
18384
+ if (cancelled) return;
18385
+ if (!data.package) {
18386
+ resolver3.setUserPackageFeatures(null);
18387
+ return;
18388
+ }
18389
+ resolver3.setUserPackageFeatures(data.features ?? {});
18390
+ } catch {
18391
+ if (!cancelled) resolver3.setUserPackageFeatures(null);
18392
+ }
18393
+ })();
18394
+ return () => {
18395
+ cancelled = true;
18396
+ };
18397
+ }, [apiUrl, getAuthToken]);
18398
+ }
18266
18399
  function LicenseRequiredOverlay({
18267
18400
  reason,
18268
18401
  onOpenLicenseSettings
@@ -22979,6 +23112,7 @@ var ChartCanvas = forwardRef(
22979
23112
  const capabilities = useChartCapabilities();
22980
23113
  const dataBlocked = useLicenseDataBlocked();
22981
23114
  useHostLicense(apiUrl, getAuthToken);
23115
+ useUserPackage(apiUrl, getAuthToken);
22982
23116
  const [indicators, setIndicators] = useState([]);
22983
23117
  const [totalHeight, setTotalHeight] = useState(600);
22984
23118
  const [activeTool, setActiveTool] = useState(initialActiveTool ?? "cursor");
@@ -26807,7 +26941,7 @@ function _guessFrontMonth(product, months) {
26807
26941
  }
26808
26942
 
26809
26943
  // src/version.ts
26810
- var FORGECHARTS_VERSION = "1.5.37" ;
26944
+ var FORGECHARTS_VERSION = "1.5.38" ;
26811
26945
  var TIMEZONE_OPTIONS = [
26812
26946
  { label: "UTC", value: "UTC" },
26813
26947
  { label: "Exchange", value: "exchange" },
@@ -31319,6 +31453,7 @@ function ChartWorkspace({
31319
31453
  const capabilities = useChartCapabilities();
31320
31454
  const dataBlocked = useLicenseDataBlocked();
31321
31455
  useHostLicense(hostApiUrl, getAuthToken);
31456
+ useUserPackage(hostApiUrl, getAuthToken);
31322
31457
  const autoTrading = tradingBridge !== void 0;
31323
31458
  const [autoOrderEntryOpen, setAutoOrderEntryOpen] = React11.useState(false);
31324
31459
  const [autoTradingPanelOpen, setAutoTradingPanelOpen] = React11.useState(false);
@@ -37670,6 +37805,6 @@ function IndicatorPane({
37670
37805
  ] });
37671
37806
  }
37672
37807
 
37673
- export { AgentFAB, AgentProvider, AssistantPanel, BottomToolbar, ChartCanvas, ChartContextMenu, ChartSettingsDialog, ChartWorkspace, CommandDispatcher, DEFAULT_FAVORITES, FloatingPanel, IndicatorLabel, IndicatorPane, IndicatorsDialog, LayoutMenu, LeftToolbar, LicenseRequiredOverlay, ManagedAppShell, MultiPaneChart, OrderTicket, PointerOverlay, RightToolbar, SymbolSearchDialog, TabBar, TopToolbar, VoiceInput, createTradingBridgeLogger, useAgent, useChartCapabilities, useHostLicense, useLicenseDataBlocked };
37808
+ export { AgentFAB, AgentProvider, AssistantPanel, BottomToolbar, ChartCanvas, ChartContextMenu, ChartSettingsDialog, ChartWorkspace, CommandDispatcher, DEFAULT_FAVORITES, FloatingPanel, IndicatorLabel, IndicatorPane, IndicatorsDialog, LayoutMenu, LeftToolbar, LicenseRequiredOverlay, ManagedAppShell, MultiPaneChart, OrderTicket, PointerOverlay, RightToolbar, SymbolSearchDialog, TabBar, TopToolbar, VoiceInput, createTradingBridgeLogger, useAgent, useChartCapabilities, useHostLicense, useLicenseDataBlocked, useUserPackage };
37674
37809
  //# sourceMappingURL=internal.js.map
37675
37810
  //# sourceMappingURL=internal.js.map