@ossy/sdk-react 1.40.3 → 3.0.1
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/README.md +47 -7
- package/build/packages/sdk-react/src/PushInvalidationSubscriber.js +1 -0
- package/build/packages/sdk-react/src/WorkspaceProvider.js +1 -1
- package/build/packages/sdk-react/src/public.index.js +1 -1
- package/build/public.index.d.ts +19 -4
- package/build/types/PushInvalidationSubscriber.d.ts +8 -0
- package/build/types/WorkspaceProvider.d.ts +8 -2
- package/build/types/public.index.d.ts +1 -0
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -45,16 +45,17 @@ function MyComponent() {
|
|
|
45
45
|
}
|
|
46
46
|
```
|
|
47
47
|
|
|
48
|
-
`WorkspaceProvider`
|
|
48
|
+
`WorkspaceProvider` provides the SDK and shared read cache. **SSE push invalidation is off by default** — enable it only where you need live cross-tab cache updates.
|
|
49
49
|
|
|
50
50
|
## API
|
|
51
51
|
|
|
52
52
|
| Export | Purpose |
|
|
53
53
|
|---|---|
|
|
54
|
-
| `WorkspaceProvider` | Provides SDK + shared read cache
|
|
54
|
+
| `WorkspaceProvider` | Provides SDK + shared read cache (optional app-wide push via `enablePushInvalidation`) |
|
|
55
|
+
| `PushInvalidationSubscriber` | Opt-in SSE invalidation for a page or subtree |
|
|
55
56
|
| `useSdk()` | Returns `{ invoke, invokeOptimistic, read, invalidate, cacheKey, sdk }` |
|
|
56
57
|
| `useRead()` | Same as `sdk.read` — hook for reactive reads |
|
|
57
|
-
| `usePushInvalidation()` |
|
|
58
|
+
| `usePushInvalidation()` | Low-level hook; prefer `PushInvalidationSubscriber` |
|
|
58
59
|
| `cacheKey(action, payload)` | Stable cache key for an action + payload |
|
|
59
60
|
| `projectionKey(projectionId, scopeId)` | Cache key for projection reads |
|
|
60
61
|
| `applyOptimisticResource()` | Fold a pending event into cached resource state |
|
|
@@ -95,11 +96,50 @@ sdk.invalidate(sdk.cacheKey(ListResources, { location }))
|
|
|
95
96
|
|
|
96
97
|
## Push invalidation
|
|
97
98
|
|
|
98
|
-
|
|
99
|
+
Push invalidation (ADR 0008 §9) opens a long-lived SSE connection to `GET /events` per subscriber. **It is disabled by default** because most pages only need fresh data after their own writes (`sdk.invalidate()` / refetch).
|
|
99
100
|
|
|
100
|
-
|
|
101
|
+
### When to enable
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
Use push only on pages or components that benefit from **background or cross-tab** updates, for example:
|
|
104
|
+
|
|
105
|
+
- Collaborative resource lists that should refresh when another user edits
|
|
106
|
+
- Long-lived dashboards or inbox views
|
|
107
|
+
- Dev tooling that watches task runs or automation
|
|
108
|
+
|
|
109
|
+
Avoid enabling it on static marketing pages, auth flows, or one-shot forms.
|
|
110
|
+
|
|
111
|
+
### Page-level (recommended)
|
|
112
|
+
|
|
113
|
+
```jsx
|
|
114
|
+
import { PushInvalidationSubscriber } from '@ossy/sdk-react'
|
|
115
|
+
|
|
116
|
+
export default function ResourcesPage() {
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
<PushInvalidationSubscriber />
|
|
120
|
+
{/* … */}
|
|
121
|
+
</>
|
|
122
|
+
)
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Requires `workspaceId` on the SDK (or same-origin workspace cookie). Must render inside `WorkspaceProvider`.
|
|
127
|
+
|
|
128
|
+
### App-wide (optional)
|
|
129
|
+
|
|
130
|
+
In `src/config.js`:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
export default {
|
|
134
|
+
enablePushInvalidation: true,
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
Or pass `enablePushInvalidation` to `WorkspaceProvider` in custom setups.
|
|
139
|
+
|
|
140
|
+
### Manual wiring
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
103
143
|
import { usePushInvalidation, useReadCacheStore } from '@ossy/sdk-react'
|
|
104
144
|
|
|
105
145
|
function MyBridge({ sdk }) {
|
|
@@ -109,7 +149,7 @@ function MyBridge({ sdk }) {
|
|
|
109
149
|
}
|
|
110
150
|
```
|
|
111
151
|
|
|
112
|
-
|
|
152
|
+
See [@ossy/sdk README](../sdk/README.md#push-invalidation-adr-0008) for server-side details.
|
|
113
153
|
|
|
114
154
|
## Cache key conventions
|
|
115
155
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useContext as r}from"react";import{Context as o}from"./WorkspaceProvider.js";import{usePushInvalidation as t}from"./usePushInvalidation.js";import{useReadCacheStore as i}from"./Cache.js";function m(){var m=r(o).sdk,e=i();return t(m,e),null}export{m as PushInvalidationSubscriber};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r,{createContext as e,useMemo as t}from"react";import{createCache as n,useReadCacheStore as o}from"./Cache.js";import{createMapCache as a}from"./cacheUtils.js";import{ReactSdk as
|
|
1
|
+
import r,{createContext as e,useMemo as t}from"react";import{createCache as n,useReadCacheStore as o}from"./Cache.js";import{createMapCache as a}from"./cacheUtils.js";import{ReactSdk as i}from"./react-sdk.js";import{usePushInvalidation as m}from"./usePushInvalidation.js";var l=e({}),s=n(a());function c(r){var e=r.sdk,t=o();return m(e,t),null}var u=function(e){var n=e.sdk,o=e.enablePushInvalidation,a=void 0!==o&&o,m=e.children,u=t(function(){return i.from(n)},[n]);return r.createElement(s,null,r.createElement(l.Provider,{value:{sdk:u}},a&&r.createElement(c,{sdk:u}),m))};export{l as Context,u as WorkspaceProvider};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{AsyncStatus}from"./asyncStatus.js";export{normalizeLocation}from"./normalizeLocation.js";export{ReactSdk}from"./react-sdk.js";export{resolveActionId,toActionRef}from"./action.js";export{Context,WorkspaceProvider}from"./WorkspaceProvider.js";export{useSdk}from"./useSdk.js";export{useRead}from"./useRead.js";export{usePushInvalidation}from"./usePushInvalidation.js";export{applyOptimisticResource,rollbackOptimisticResource}from"./optimisticResource.js";export{cacheKey,projectionKey}from"./cacheKey.js";export{stableSerialize}from"./stableSerialize.js";export{useReadCacheStore}from"./Cache.js";
|
|
1
|
+
export{AsyncStatus}from"./asyncStatus.js";export{normalizeLocation}from"./normalizeLocation.js";export{ReactSdk}from"./react-sdk.js";export{resolveActionId,toActionRef}from"./action.js";export{Context,WorkspaceProvider}from"./WorkspaceProvider.js";export{PushInvalidationSubscriber}from"./PushInvalidationSubscriber.js";export{useSdk}from"./useSdk.js";export{useRead}from"./useRead.js";export{usePushInvalidation}from"./usePushInvalidation.js";export{applyOptimisticResource,rollbackOptimisticResource}from"./optimisticResource.js";export{cacheKey,projectionKey}from"./cacheKey.js";export{stableSerialize}from"./stableSerialize.js";export{useReadCacheStore}from"./Cache.js";
|
package/build/public.index.d.ts
CHANGED
|
@@ -65,9 +65,24 @@ declare const Context: React.Context<Config>;
|
|
|
65
65
|
interface Config {
|
|
66
66
|
sdk: ReactSdk;
|
|
67
67
|
}
|
|
68
|
-
|
|
68
|
+
interface WorkspaceProviderProps {
|
|
69
69
|
sdk: SDK | ReactSdk;
|
|
70
|
-
|
|
70
|
+
/**
|
|
71
|
+
* When true, subscribe to SSE push for the whole app tree.
|
|
72
|
+
* Default false — prefer {@link PushInvalidationSubscriber} on specific pages.
|
|
73
|
+
*/
|
|
74
|
+
enablePushInvalidation?: boolean;
|
|
75
|
+
}
|
|
76
|
+
declare const WorkspaceProvider: ({ sdk, enablePushInvalidation, children, }: PropsWithChildren<WorkspaceProviderProps>) => React.JSX.Element;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Opt-in SSE push invalidation for a page or subtree.
|
|
80
|
+
*
|
|
81
|
+
* Mount only where live cache invalidation matters (e.g. collaborative lists,
|
|
82
|
+
* long-lived dashboards). Most pages should rely on `sdk.invalidate()` after
|
|
83
|
+
* writes instead — see sdk-react README § Push invalidation.
|
|
84
|
+
*/
|
|
85
|
+
declare function PushInvalidationSubscriber(): null;
|
|
71
86
|
|
|
72
87
|
declare function projectionKey(projectionId: string, scopeId: string): string;
|
|
73
88
|
declare function cacheKey(action: ActionRef | string, payload?: Record<string, unknown>): string;
|
|
@@ -139,5 +154,5 @@ declare function usePushInvalidation(sdk: {
|
|
|
139
154
|
/** Deterministic JSON for cache keys — sorted object keys, no Ramda. */
|
|
140
155
|
declare function stableSerialize(value: unknown): string;
|
|
141
156
|
|
|
142
|
-
export { AsyncStatus, Context, ReactSdk, WorkspaceProvider, applyOptimisticResource, cacheKey, normalizeLocation, projectionKey, resolveActionId, rollbackOptimisticResource, stableSerialize, toActionRef, usePushInvalidation, useRead, useReadCacheStore, useSdk };
|
|
143
|
-
export type { ActionRef, AsyncStatusType, Config, OptimisticResourceEvent, ReadOptions, ReadResult, SdkApi };
|
|
157
|
+
export { AsyncStatus, Context, PushInvalidationSubscriber, ReactSdk, WorkspaceProvider, applyOptimisticResource, cacheKey, normalizeLocation, projectionKey, resolveActionId, rollbackOptimisticResource, stableSerialize, toActionRef, usePushInvalidation, useRead, useReadCacheStore, useSdk };
|
|
158
|
+
export type { ActionRef, AsyncStatusType, Config, OptimisticResourceEvent, ReadOptions, ReadResult, SdkApi, WorkspaceProviderProps };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Opt-in SSE push invalidation for a page or subtree.
|
|
3
|
+
*
|
|
4
|
+
* Mount only where live cache invalidation matters (e.g. collaborative lists,
|
|
5
|
+
* long-lived dashboards). Most pages should rely on `sdk.invalidate()` after
|
|
6
|
+
* writes instead — see sdk-react README § Push invalidation.
|
|
7
|
+
*/
|
|
8
|
+
export function PushInvalidationSubscriber(): null;
|
|
@@ -5,6 +5,12 @@ export declare const Context: React.Context<Config>;
|
|
|
5
5
|
export interface Config {
|
|
6
6
|
sdk: ReactSdk;
|
|
7
7
|
}
|
|
8
|
-
export
|
|
8
|
+
export interface WorkspaceProviderProps {
|
|
9
9
|
sdk: SDK | ReactSdk;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* When true, subscribe to SSE push for the whole app tree.
|
|
12
|
+
* Default false — prefer {@link PushInvalidationSubscriber} on specific pages.
|
|
13
|
+
*/
|
|
14
|
+
enablePushInvalidation?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare const WorkspaceProvider: ({ sdk, enablePushInvalidation, children, }: PropsWithChildren<WorkspaceProviderProps>) => React.JSX.Element;
|
|
@@ -3,6 +3,7 @@ export * from './normalizeLocation';
|
|
|
3
3
|
export * from './react-sdk';
|
|
4
4
|
export * from './action';
|
|
5
5
|
export * from './WorkspaceProvider';
|
|
6
|
+
export { PushInvalidationSubscriber } from './PushInvalidationSubscriber.jsx';
|
|
6
7
|
export * from './useSdk';
|
|
7
8
|
export * from './useRead';
|
|
8
9
|
export * from './usePushInvalidation';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/sdk-react",
|
|
3
3
|
"description": "Software Development Kit React",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "3.0.1",
|
|
5
5
|
"url": "git://github.com/ossy-se/packages/sdk-react",
|
|
6
6
|
"source": "src/public.index.ts",
|
|
7
7
|
"main": "./build/packages/sdk-react/src/public.index.js",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"@babel/preset-typescript": "^7.26.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"@ossy/fold": ">=1.0.0 <
|
|
44
|
-
"@ossy/sdk": ">=1.0.0 <
|
|
43
|
+
"@ossy/fold": ">=1.0.0 <4.0.0",
|
|
44
|
+
"@ossy/sdk": ">=1.0.0 <4.0.0",
|
|
45
45
|
"react": ">=19.0.0 <20.0.0",
|
|
46
46
|
"react-dom": ">=19.0.0 <20.0.0"
|
|
47
47
|
},
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"/build",
|
|
54
54
|
"README.md"
|
|
55
55
|
],
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "4a70ec216448680d2fddc57b2a8a0077489720ae"
|
|
57
57
|
}
|