@stackable-labs/sdk-extension-react 1.103.0 → 2.1.0

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { ApiRequest, FetchRequestInit, FetchResponse, ToastPayload, InvokeAction, ContextData, IdentityBaseClaims, IdentityEventType, IdentityEvent, ExtendIdentityHandler, MessagingEventType, MessagingEventHandler, ActivityEventType, ActivityEventHandler, EventType, AllowedIconName } from '@stackable-labs/sdk-extension-contracts';
2
+ import { InvokeAction, ToastPayload, ContextData, FetchRequestInit, FetchResponse, ApiRequest, IdentityBaseClaims, IdentityEventType, IdentityEvent, ExtendIdentityHandler, MessagingEventType, MessagingEventHandler, ActivityEventType, ActivityEventHandler, EventType, AllowedIconName } from '@stackable-labs/sdk-extension-contracts';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  /**
@@ -54,7 +54,40 @@ interface ExtensionContextValue {
54
54
  */
55
55
  declare const useSurfaceContext: () => Record<string, unknown>;
56
56
  /**
57
- * Access host-mediated capabilities (data, actions, context).
57
+ * Per-capability primitives each is a separate top-level named export
58
+ * carrying ONLY its own capability literal (e.g. `'data.query'`).
59
+ *
60
+ * NOTE: these are NOT React hooks. The `*Capability` suffix is deliberate —
61
+ * each is a thin wrapper around `callCapability(...)` exposed as an
62
+ * independent export so that Rollup/Vite can tree-shake unused capabilities
63
+ * out of an extension's `dist/extension.js`. That, combined with each SDK
64
+ * package's `"sideEffects": false`, is what makes `bundle-scan.ts` stop
65
+ * raising spurious `undeclared_permission` errors (STA-157).
66
+ *
67
+ * Tree-shaking only works because each capability is its own export. The
68
+ * `useCapabilities()` aggregator below still references all 6 — anyone who
69
+ * uses it gets every literal in their bundle, by design (accepted trade-off
70
+ * for the ergonomic single-import surface). Prefer the per-capability
71
+ * exports for new code when bundle size or scanner cleanliness matters.
72
+ */
73
+ declare const contextReadCapability: () => Promise<ContextData>;
74
+ declare const dataQueryCapability: <T = unknown>(payload: ApiRequest) => Promise<T>;
75
+ declare const dataFetchCapability: (url: string, init?: FetchRequestInit) => Promise<FetchResponse>;
76
+ declare const actionsToastCapability: (payload: ToastPayload) => Promise<void>;
77
+ declare const actionsInvokeCapability: <T = unknown>(action: InvokeAction, payload?: Record<string, unknown>) => Promise<T>;
78
+ declare const extendIdentityCapability: (payload: {
79
+ claims: IdentityBaseClaims;
80
+ }) => Promise<{
81
+ additionalClaims: Record<string, unknown>;
82
+ }>;
83
+ /**
84
+ * Access host-mediated capabilities (data, actions, context, extend).
85
+ *
86
+ * Aggregator. References every per-capability primitive above as a function,
87
+ * so a consumer that imports `useCapabilities` pulls all 6 capability
88
+ * literals into their bundle. First-class part of the API — supported
89
+ * indefinitely. Per-capability primitives (`*Capability`) are preferred for
90
+ * new code when bundle size or scanner cleanliness matters.
58
91
  */
59
92
  declare const useCapabilities: () => {
60
93
  data: {
@@ -592,4 +625,4 @@ declare const useContextData: () => UseContextDataResult;
592
625
  */
593
626
  declare const useSettings: () => Record<string, unknown>;
594
627
 
595
- export { type Store, Surface, createExtension, createStore, ui, useActivityEvent, useCapabilities, useContextData, useEvent, useExtendIdentity, useExtension, useIdentityEvent, useMessagingEvent, useSettings, useStore, useSurfaceContext };
628
+ export { type Store, Surface, actionsInvokeCapability, actionsToastCapability, contextReadCapability, createExtension, createStore, dataFetchCapability, dataQueryCapability, extendIdentityCapability, ui, useActivityEvent, useCapabilities, useContextData, useEvent, useExtendIdentity, useExtension, useIdentityEvent, useMessagingEvent, useSettings, useStore, useSurfaceContext };
package/dist/index.js CHANGED
@@ -203,21 +203,17 @@ var useSurfaceContext = () => {
203
203
  }
204
204
  return ctx;
205
205
  };
206
+ var contextReadCapability = () => callCapability("context.read");
207
+ var dataQueryCapability = (payload) => callCapability("data.query", payload);
208
+ var dataFetchCapability = (url, init) => callCapability("data.fetch", { url, ...init });
209
+ var actionsToastCapability = (payload) => callCapability("actions.toast", payload);
210
+ var actionsInvokeCapability = (action, payload) => callCapability("actions.invoke", { action, payload });
211
+ var extendIdentityCapability = (payload) => callCapability("extend.identity", payload);
206
212
  var useCapabilities = () => ({
207
- data: {
208
- query: (payload) => callCapability("data.query", payload),
209
- fetch: (url, init) => callCapability("data.fetch", { url, ...init })
210
- },
211
- actions: {
212
- toast: (payload) => callCapability("actions.toast", payload),
213
- invoke: (action, payload) => callCapability("actions.invoke", { action, payload })
214
- },
215
- context: {
216
- read: () => callCapability("context.read")
217
- },
218
- extend: {
219
- identity: (payload) => callCapability("extend.identity", payload)
220
- }
213
+ data: { query: dataQueryCapability, fetch: dataFetchCapability },
214
+ actions: { toast: actionsToastCapability, invoke: actionsInvokeCapability },
215
+ context: { read: contextReadCapability },
216
+ extend: { identity: extendIdentityCapability }
221
217
  });
222
218
  var useStore = (store, selector) => {
223
219
  const select = selector ?? ((s) => s);
@@ -549,13 +545,12 @@ var FooterLink = (props) => /* @__PURE__ */ jsx(
549
545
  var Menu = (props) => /* @__PURE__ */ jsx("ui-menu", { ...props, children: props.children });
550
546
  var MenuItem = (props) => /* @__PURE__ */ jsx("ui-menu-item", { ...props });
551
547
  var useContextData = () => {
552
- const capabilities = useCapabilities();
553
548
  const [contextData, setContextData] = useState({});
554
549
  const [loading, setLoading] = useState(true);
555
550
  useEffect(() => {
556
551
  const loadContext = async () => {
557
552
  try {
558
- const ctx = await capabilities.context.read();
553
+ const ctx = await contextReadCapability();
559
554
  setContextData(ctx);
560
555
  } catch (err) {
561
556
  console.error("Failed to read context:", err);
@@ -584,4 +579,4 @@ var useSettings = () => {
584
579
  return settings ?? {};
585
580
  };
586
581
 
587
- export { Surface, createExtension, createStore, ui_exports as ui, useActivityEvent, useCapabilities, useContextData, useEvent, useExtendIdentity, useExtension, useIdentityEvent, useMessagingEvent, useSettings, useStore, useSurfaceContext };
582
+ export { Surface, actionsInvokeCapability, actionsToastCapability, contextReadCapability, createExtension, createStore, dataFetchCapability, dataQueryCapability, extendIdentityCapability, ui_exports as ui, useActivityEvent, useCapabilities, useContextData, useEvent, useExtendIdentity, useExtension, useIdentityEvent, useMessagingEvent, useSettings, useStore, useSurfaceContext };
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@stackable-labs/sdk-extension-react",
3
- "version": "1.103.0",
3
+ "version": "2.1.0",
4
4
  "type": "module",
5
+ "sideEffects": false,
5
6
  "private": false,
6
7
  "main": "./dist/index.js",
7
8
  "types": "./dist/index.d.ts",