@ossy/sdk-react 1.40.0 → 1.40.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 +59 -64
- package/build/node_modules/tslib/tslib.es6.js +1 -1
- package/build/packages/sdk-react/src/Cache.js +1 -1
- package/build/packages/sdk-react/src/WorkspaceProvider.js +1 -1
- package/build/packages/sdk-react/src/action.js +1 -0
- package/build/packages/sdk-react/src/cacheEntry.js +1 -0
- package/build/packages/sdk-react/src/cacheKey.js +1 -0
- package/build/packages/sdk-react/src/normalizeLocation.js +1 -0
- package/build/packages/sdk-react/src/public.index.js +1 -1
- package/build/packages/sdk-react/src/react-sdk.js +1 -0
- package/build/packages/sdk-react/src/stableSerialize.js +1 -0
- package/build/packages/sdk-react/src/useRead.js +1 -0
- package/build/packages/sdk-react/src/useSdk.js +1 -1
- package/build/public.index.d.ts +74 -108
- package/build/types/Cache.d.ts +11 -1
- package/build/types/WorkspaceProvider.d.ts +6 -3
- package/build/types/action.d.ts +8 -0
- package/build/types/cacheEntry.d.ts +7 -0
- package/build/types/cacheKey.d.ts +2 -0
- package/build/types/normalizeLocation.d.ts +2 -0
- package/build/types/public.index.d.ts +6 -10
- package/build/types/react-sdk.d.ts +39 -0
- package/build/types/stableSerialize.d.ts +2 -0
- package/build/types/useRead.d.ts +15 -0
- package/build/types/useSdk.d.ts +11 -1
- package/package.json +2 -2
- package/build/packages/sdk-react/src/removeBy.js +0 -1
- package/build/packages/sdk-react/src/replaceBy.js +0 -1
- package/build/packages/sdk-react/src/useApiTokens.js +0 -1
- package/build/packages/sdk-react/src/useAuthentication.js +0 -1
- package/build/packages/sdk-react/src/useQuery.js +0 -1
- package/build/packages/sdk-react/src/useResource.js +0 -1
- package/build/packages/sdk-react/src/useResourceTemplate.js +0 -1
- package/build/packages/sdk-react/src/useResources.js +0 -1
- package/build/packages/sdk-react/src/useUser.js +0 -1
- package/build/packages/sdk-react/src/useUsers.js +0 -1
- package/build/packages/sdk-react/src/useWorkspace.js +0 -1
- package/build/packages/sdk-react/src/useWorkspaces.js +0 -1
- package/build/types/removeBy.d.ts +0 -1
- package/build/types/replaceBy.d.ts +0 -1
- package/build/types/useApiTokens.d.ts +0 -10
- package/build/types/useAuthentication.d.ts +0 -20
- package/build/types/useQuery.d.ts +0 -6
- package/build/types/useResource.d.ts +0 -12
- package/build/types/useResourceTemplate.d.ts +0 -1
- package/build/types/useResources.d.ts +0 -21
- package/build/types/useUser.d.ts +0 -5
- package/build/types/useUsers.d.ts +0 -6
- package/build/types/useWorkspace.d.ts +0 -10
- package/build/types/useWorkspaces.d.ts +0 -7
package/README.md
CHANGED
|
@@ -1,101 +1,96 @@
|
|
|
1
1
|
# React bindings
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
with react hooks you can use to fetch data.
|
|
3
|
+
Thin React layer over `@ossy/sdk`. One hook — **`useSdk()`** — for reads, writes, and cache invalidation.
|
|
5
4
|
|
|
6
5
|
## Getting started
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
```
|
|
7
|
+
```bash
|
|
11
8
|
npm install @ossy/sdk-react @ossy/sdk
|
|
12
9
|
```
|
|
13
10
|
|
|
14
|
-
Create an SDK instance and wrap your app in `<WorkspaceProvider />` to handle
|
|
15
|
-
data storage and configuration:
|
|
16
|
-
|
|
17
11
|
```jsx
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { MyComponent } from './MyComponent.jsx'
|
|
12
|
+
import { WorkspaceProvider, useSdk, AsyncStatus } from '@ossy/sdk-react'
|
|
13
|
+
import { ReactSdk } from '@ossy/sdk-react'
|
|
14
|
+
import { ListResources, CreateResource } from '@ossy/resources'
|
|
22
15
|
|
|
23
|
-
const sdk =
|
|
16
|
+
const sdk = ReactSdk.of({
|
|
17
|
+
workspaceId: 'your-workspace-id',
|
|
18
|
+
apiUrl: 'https://api.ossy.se/api/v0',
|
|
19
|
+
})
|
|
24
20
|
|
|
25
21
|
export const App = () => (
|
|
26
22
|
<WorkspaceProvider sdk={sdk}>
|
|
27
23
|
<MyComponent />
|
|
28
24
|
</WorkspaceProvider>
|
|
29
25
|
)
|
|
30
|
-
```
|
|
31
|
-
```jsx
|
|
32
|
-
// MyComponent.jsx
|
|
33
|
-
import { useResources } from '@ossy/sdk-react'
|
|
34
26
|
|
|
35
|
-
|
|
36
|
-
const
|
|
27
|
+
function MyComponent() {
|
|
28
|
+
const sdk = useSdk()
|
|
29
|
+
const location = '/@ossy/domains/'
|
|
30
|
+
const { status, data: resources, error, refetch } = sdk.read(ListResources, { location })
|
|
31
|
+
|
|
32
|
+
const handleCreate = async () => {
|
|
33
|
+
await sdk.invoke(CreateResource, { type: 'document', location, name: 'Hello', content: {} })
|
|
34
|
+
sdk.invalidate(sdk.cacheKey(ListResources, { location }))
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (status === AsyncStatus.Loading) return <>Loading…</>
|
|
37
38
|
|
|
38
39
|
return (
|
|
39
40
|
<>
|
|
40
|
-
{
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
{ status === 'Loading' && (
|
|
45
|
-
<>Loading...</>
|
|
46
|
-
)}
|
|
47
|
-
|
|
48
|
-
{ status === 'Success' && (
|
|
49
|
-
resources.map(resource => (
|
|
50
|
-
<div key={resource.id}>
|
|
51
|
-
{resource.name}
|
|
52
|
-
</div>
|
|
53
|
-
))
|
|
54
|
-
)}
|
|
55
|
-
</>
|
|
41
|
+
<button onClick={handleCreate}>Create</button>
|
|
42
|
+
{resources?.map((r) => <div key={r.id}>{r.name}</div>)}
|
|
43
|
+
</>
|
|
56
44
|
)
|
|
57
45
|
}
|
|
58
46
|
```
|
|
59
47
|
|
|
60
|
-
##
|
|
48
|
+
## API
|
|
61
49
|
|
|
62
|
-
|
|
50
|
+
| Export | Purpose |
|
|
51
|
+
|---|---|
|
|
52
|
+
| `WorkspaceProvider` | Provides SDK + shared read cache |
|
|
53
|
+
| `useSdk()` | Returns `{ invoke, read, invalidate, cacheKey, sdk }` |
|
|
54
|
+
| `useRead()` | Same as `sdk.read` — hook for reactive reads |
|
|
55
|
+
| `cacheKey(action, payload)` | Stable cache key for an action + payload |
|
|
56
|
+
| `ReactSdk` | Browser SDK with `invoke(action, payload)` |
|
|
57
|
+
| `ActionRef` | Platform action POJO type `{ id, access? }` |
|
|
58
|
+
| `resolveActionId()` | Normalize dot ids to slash (`booking.create` → `booking/create`) |
|
|
59
|
+
| `AsyncStatus` | Loading state constants for UI |
|
|
60
|
+
| `normalizeLocation()` | Normalize resource location paths |
|
|
61
|
+
| `stableSerialize()` | Deterministic JSON for cache keys |
|
|
63
62
|
|
|
64
|
-
|
|
65
|
-
const { status, resources, loadResources } = useResources('/')
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
**Parameters**
|
|
63
|
+
## `useSdk()` shape
|
|
69
64
|
|
|
70
|
-
|
|
65
|
+
```ts
|
|
66
|
+
const sdk = useSdk()
|
|
71
67
|
|
|
72
|
-
|
|
68
|
+
// Reactive read — re-renders when cache updates
|
|
69
|
+
const { status, data, error, refetch } = sdk.read(ListResources, { location })
|
|
73
70
|
|
|
74
|
-
|
|
71
|
+
// Command
|
|
72
|
+
await sdk.invoke(CreateResource, payload)
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
loading is not Success
|
|
81
|
-
- **loadResources** - Function to manually refetch the resource list
|
|
74
|
+
// Invalidate cache (triggers re-fetch on next read)
|
|
75
|
+
sdk.invalidate('location:/@ossy/domains/')
|
|
76
|
+
sdk.invalidate(sdk.cacheKey(ListResources, { location }))
|
|
77
|
+
```
|
|
82
78
|
|
|
83
|
-
|
|
79
|
+
`read` is a React hook — call it unconditionally at the top of your component (same rules as `useState`).
|
|
84
80
|
|
|
85
|
-
|
|
86
|
-
const { status, resource } = useResource('resourceId')
|
|
87
|
-
```
|
|
81
|
+
## Cache key conventions
|
|
88
82
|
|
|
89
|
-
|
|
83
|
+
| Action + payload | Cache key |
|
|
84
|
+
|---|---|
|
|
85
|
+
| `resources/list` + `{ location }` | `location:${normalizeLocation(location)}` |
|
|
86
|
+
| `resources/search` + query | `search:${stableSerialize(query)}` |
|
|
87
|
+
| `resources/get` + `{ id }` | `resource:${id}` |
|
|
88
|
+
| default | `action:${actionId}` or `action:${actionId}:${stableSerialize(payload)}` |
|
|
90
89
|
|
|
91
|
-
|
|
90
|
+
Import action POJOs from feature packages (`@ossy/resources`, `@ossy/workspaces`, …). Action ids use slash notation (`booking/create`).
|
|
92
91
|
|
|
93
|
-
|
|
92
|
+
## Dependencies
|
|
94
93
|
|
|
95
|
-
|
|
94
|
+
Peer dependencies: `@ossy/sdk`, `react`, `react-dom`.
|
|
96
95
|
|
|
97
|
-
|
|
98
|
-
Can be used to show loading indicators or error screens.
|
|
99
|
-
Possible values are: NotInitialized, Loading, Success, Error
|
|
100
|
-
- **resource** - The fetched resource, defaults to an empty object
|
|
101
|
-
when status is not Success
|
|
96
|
+
No Ramda.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var r=function(){return r=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return r},r.apply(this,arguments)};
|
|
1
|
+
var r=function(){return r=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++)for(var o in t=arguments[e])Object.prototype.hasOwnProperty.call(t,o)&&(r[o]=t[o]);return r},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;export{r as __assign};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{__assign as
|
|
1
|
+
import{__assign as r}from"../../../node_modules/tslib/tslib.es6.js";import t,{createContext as e,useContext as n,useReducer as u,useRef as a,useCallback as o,useMemo as c}from"react";import{AsyncStatus as i}from"./asyncStatus.js";import{emptyEntry as f}from"./cacheEntry.js";var s=e({}),l="SET",d="INVALIDATE",v=function(e){var n=e.get,v=e.set,y=e.getInitialState;return function(e){var h,p=null!==(h=null==y?void 0:y())&&void 0!==h?h:{},g=u(function(r){var t=r.set,e=r.get,n=r.getInitialState;return function(r,u){var a,o=null!==(a=null==n?void 0:n())&&void 0!==a?a:{};switch(void 0===r&&(r=o),u.type){case l:var c=void 0;if("function"==typeof u.data){var i=e(u.cacheKey,r);c=u.data(i)}else c=u.data;return t(u.cacheKey,c,r);case d:for(var s=r,v=0,y=u.keys;v<y.length;v++){var h=y[v];s=t(h,f(),s)}return s;default:return r}}}({set:v,get:n,getInitialState:y}),void 0,function(){return p}),E=g[0],S=g[1],m=a(new Set),w=a(new Map),I=o(function(){m.current.forEach(function(r){return r()})},[]),b=o(function(r){return function(t){S({type:l,cacheKey:r,data:t}),I()}},[I]),A=o(function(r){return n(r,E)},[E,n]),K=o(function(r){var t=n(r,E);return null!=t?t:f()},[E,n]),j=o(function(r,t){S({type:l,cacheKey:r,data:"function"==typeof t?function(r){return t(null!=r?r:f())}:t}),I()},[I]),k=o(function(r){var t=Array.isArray(r)?r:[r];w.current.forEach(function(r,e){t.includes(e)&&w.current.delete(e)}),S({type:d,keys:t}),I()},[I]),L=o(function(r){return m.current.add(r),function(){return m.current.delete(r)}},[]),P=o(function(t,e){var n=w.current.get(t);if(n)return n;j(t,function(t){return r(r({},t),{status:i.Loading,error:null})});var u=e().then(function(r){return j(t,{status:i.Success,data:r,error:null}),r}).catch(function(r){var e=r instanceof Error?r:new Error(String(r));throw j(t,{status:i.Error,data:void 0,error:e}),e}).finally(function(){w.current.delete(t)});return w.current.set(t,u),u},[j]),T=c(function(){return{getEntry:K,setEntry:j,invalidate:k,subscribe:L,fetch:P}},[K,j,k,L,P]);return t.createElement(s.Provider,{value:{get:A,set:b,readStore:T}},e.children)}},y=function(){var r=n(s).readStore;if(!r)throw new Error("useReadCacheStore requires WorkspaceProvider");return r};export{s as CacheContext,v as createCache,y as useReadCacheStore};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import r,{createContext as e}from"react";import{createCache as
|
|
1
|
+
import r,{createContext as e,useMemo as t}from"react";import{createCache as o}from"./Cache.js";import{createMapCache as m}from"./cacheUtils.js";import{ReactSdk as c}from"./react-sdk.js";var n=e({}),a=o(m()),i=function(e){var o=e.sdk,m=e.children,i=t(function(){return c.from(o)},[o]);return r.createElement(a,null,r.createElement(n.Provider,{value:{sdk:i}},m))};export{n as Context,i as WorkspaceProvider};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__assign as r}from"../../../node_modules/tslib/tslib.es6.js";function t(r){var t="string"==typeof r?r:r.id;return t.includes(".")?t.replace(/\./g,"/"):t}function e(e){var i=t(e);return"string"==typeof e?{id:i}:r(r({},e),{id:i})}export{t as resolveActionId,e as toActionRef};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var t=function(){return{status:"NotInitialized",data:void 0,error:null}};export{t as emptyEntry};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{resolveActionId as o}from"./action.js";import{normalizeLocation as r}from"./normalizeLocation.js";import{stableSerialize as t}from"./stableSerialize.js";function c(c,n){var i=o(c);if("resources/list"===i){var a=null==n?void 0:n.location;return"location:".concat(r("string"==typeof a?a:void 0))}if("resources/search"===i)return"search:".concat(t(null!=n?n:{}));if("resources/get"===i){var e=null==n?void 0:n.id;return"resource:".concat(null!=e?e:"")}var s=t(n);return s?"action:".concat(i,":").concat(s):"action:".concat(i)}export{c as cacheKey};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(r){if(null==r||""===r)return"/";var n=r.replace(/^\/+|\/+$/g,"");return n?"/".concat(n,"/"):"/"}export{r as normalizeLocation};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export{AsyncStatus}from"./asyncStatus.js";export{
|
|
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{cacheKey}from"./cacheKey.js";export{stableSerialize}from"./stableSerialize.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{SDK as e}from"@ossy/sdk";import{toActionRef as t}from"./action.js";export{resolveActionId}from"./action.js";var o=function(){function o(e){this.sdk=e}return Object.defineProperty(o.prototype,"workspaceId",{get:function(){return this.sdk.workspaceId},enumerable:!1,configurable:!0}),Object.defineProperty(o.prototype,"authorization",{get:function(){return this.sdk.authorization},enumerable:!1,configurable:!0}),o.prototype.updateConfig=function(e){return this.sdk.updateConfig(e),this},o.prototype.invoke=function(e,o){return this.sdk.invoke(t(e),o)},Object.defineProperty(o.prototype,"resources",{get:function(){return this.sdk.resources},enumerable:!1,configurable:!0}),o.from=function(e){return e instanceof o?e:new o(e)},o.of=function(t){return new o(e.of(t))},o}();export{o as ReactSdk};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function r(n){if(null==n)return"";if("object"!=typeof n)return JSON.stringify(n);if(Array.isArray(n))return"[".concat(n.map(r).join(","),"]");var t=n,i=Object.keys(t).sort().filter(function(r){return void 0!==t[r]}).map(function(n){return"".concat(JSON.stringify(n),":").concat(r(t[n]))});return"{".concat(i.join(","),"}")}export{r as stableSerialize};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useContext as t,useMemo as r,useCallback as n,useSyncExternalStore as o,useEffect as e}from"react";import{toActionRef as s}from"./action.js";import{AsyncStatus as a}from"./asyncStatus.js";import{cacheKey as u}from"./cacheKey.js";import{useReadCacheStore as c}from"./Cache.js";import{Context as i}from"./WorkspaceProvider.js";function f(f,m,d){var p=t(i).sdk,v=c(),h=r(function(){return u(f,m)},[f,m]),j=!1!==(null==d?void 0:d.enabled),k=n(function(){return v.getEntry(h)},[v,h]),l=o(v.subscribe,k,k);e(function(){j&&l.status!==a.Loading&&l.status!==a.Success&&l.status!==a.Error&&v.fetch(h,function(){return p.invoke(s(f),m)}).catch(function(){})},[j,h,l.status,v,p,f,m]);var b=n(function(){return v.invalidate(h),v.fetch(h,function(){return p.invoke(s(f),m)})},[v,h,p,f,m]);return{status:l.status,data:l.data,error:l.error,refetch:b}}export{u as cacheKey,f as useRead};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useContext as r}from"react";import{Context as
|
|
1
|
+
import{useContext as r,useCallback as e,useMemo as o}from"react";import{cacheKey as i}from"./cacheKey.js";import{Context as t}from"./WorkspaceProvider.js";import{useReadCacheStore as n}from"./Cache.js";import{useRead as a}from"./useRead.js";function c(){var c=r(t).sdk,m=n(),f=e(function(r){m.invalidate(r)},[m]),s=e(function(r,e){return c.invoke(r,e)},[c]);return o(function(){return{invoke:s,read:a,invalidate:f,cacheKey:i,sdk:c}},[s,f,c])}export{c as useSdk};
|
package/build/public.index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
+
import { SDK, SDKConfig } from '@ossy/sdk';
|
|
1
2
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import * as _ossy_sdk from '@ossy/sdk';
|
|
3
|
-
import { SDK } from '@ossy/sdk';
|
|
4
3
|
|
|
5
4
|
declare const AsyncStatus: {
|
|
6
5
|
readonly NotInitialized: "NotInitialized";
|
|
@@ -10,121 +9,88 @@ declare const AsyncStatus: {
|
|
|
10
9
|
};
|
|
11
10
|
type AsyncStatusType = (typeof AsyncStatus)[keyof typeof AsyncStatus];
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
tokens: any;
|
|
16
|
-
createApiToken: (token: {
|
|
17
|
-
name: string;
|
|
18
|
-
description: string;
|
|
19
|
-
expiresAt: string;
|
|
20
|
-
}) => Promise<any>;
|
|
21
|
-
invalidateApiToken: (id: string) => Promise<any>;
|
|
22
|
-
};
|
|
12
|
+
/** Normalize location to match API: single leading and trailing slash. */
|
|
13
|
+
declare function normalizeLocation(loc: string | undefined): string;
|
|
23
14
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
NotInitialized: string;
|
|
27
|
-
NotAuthenticated: string;
|
|
28
|
-
Verifying: string;
|
|
29
|
-
Authenticated: string;
|
|
30
|
-
VerifySignIn: string;
|
|
31
|
-
};
|
|
32
|
-
declare const useAuthentication: () => {
|
|
33
|
-
status: any;
|
|
34
|
-
signUp: (payload: {
|
|
35
|
-
email: string;
|
|
36
|
-
firstName: string;
|
|
37
|
-
lastName: string;
|
|
38
|
-
}) => Promise<any>;
|
|
39
|
-
signIn: (email: any) => Promise<any>;
|
|
40
|
-
signOff: () => Promise<any>;
|
|
41
|
-
verifySignIn: (token: string) => Promise<any>;
|
|
42
|
-
verifyInvitation: (workspaceId: string, token: string) => Promise<any>;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
declare const useWorkspace: (props?: {
|
|
15
|
+
/** Platform action POJO exported from feature `*.action.js` files. */
|
|
16
|
+
type ActionRef = {
|
|
46
17
|
id: string;
|
|
47
|
-
|
|
48
|
-
status: any;
|
|
49
|
-
workspace: any;
|
|
50
|
-
error: any;
|
|
51
|
-
loadWorkspace: () => void;
|
|
52
|
-
createApiToken: (description: string) => Promise<string>;
|
|
53
|
-
inviteUser: (email: string) => Promise<any>;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
declare const useWorkspaces: () => {
|
|
57
|
-
status: any;
|
|
58
|
-
workspaces: any;
|
|
59
|
-
error: any;
|
|
60
|
-
loadWorkspaces: () => void;
|
|
61
|
-
createWorkspace: (name: string) => Promise<any>;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
declare const useQuery: (incomingQuery: any) => {
|
|
65
|
-
status: any;
|
|
66
|
-
resources: any;
|
|
67
|
-
error: any;
|
|
68
|
-
loadResources: (query: any) => void;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
declare const useResource: (id: string) => {
|
|
72
|
-
status: any;
|
|
73
|
-
resource: any;
|
|
74
|
-
error: any;
|
|
75
|
-
loadResource: () => void;
|
|
76
|
-
removeResource: () => Promise<void>;
|
|
77
|
-
updateResourceContent: (content: any) => Promise<any>;
|
|
78
|
-
renameResource: (name: string) => Promise<any>;
|
|
79
|
-
access: ({ access }: {
|
|
80
|
-
access: "restricted" | "public";
|
|
81
|
-
}) => Promise<any>;
|
|
18
|
+
access?: string;
|
|
82
19
|
};
|
|
20
|
+
/** Normalize dot aliases to slash ids (`booking.create` → `booking/create`). */
|
|
21
|
+
declare function resolveActionId(action: ActionRef | string): string;
|
|
22
|
+
declare function toActionRef(action: ActionRef | string): ActionRef;
|
|
83
23
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
24
|
+
/**
|
|
25
|
+
* Browser SDK for React apps. Dispatch platform actions with `invoke(action, payload)`.
|
|
26
|
+
*/
|
|
27
|
+
declare class ReactSdk {
|
|
28
|
+
private sdk;
|
|
29
|
+
constructor(sdk: SDK);
|
|
30
|
+
get workspaceId(): string | undefined;
|
|
31
|
+
get authorization(): string | undefined;
|
|
32
|
+
updateConfig(config: SDKConfig): this;
|
|
33
|
+
invoke<TPayload extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>(action: ActionRef | string, payload?: TPayload): Promise<TResult>;
|
|
34
|
+
/** @deprecated Use `invoke(action, payload)`. Kept for transitional resource uploads. */
|
|
35
|
+
get resources(): {
|
|
36
|
+
upload: ({ location, file }: {
|
|
37
|
+
location: string;
|
|
38
|
+
file: File;
|
|
39
|
+
}) => Promise<{
|
|
40
|
+
content: {
|
|
41
|
+
uploadUrl: string;
|
|
42
|
+
};
|
|
43
|
+
}>;
|
|
44
|
+
list: (query: {
|
|
45
|
+
location?: string;
|
|
46
|
+
}) => Promise<unknown>;
|
|
47
|
+
uploadNamedVersion: ({ id, name, file }: {
|
|
48
|
+
id: string;
|
|
49
|
+
name: string;
|
|
50
|
+
file: File;
|
|
51
|
+
}) => Promise<{
|
|
52
|
+
content: {
|
|
53
|
+
uploadUrl: string;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
};
|
|
57
|
+
static from(sdk: SDK | ReactSdk): ReactSdk;
|
|
58
|
+
static of(config: SDKConfig): ReactSdk;
|
|
59
|
+
}
|
|
107
60
|
|
|
108
61
|
declare const Context: React.Context<Config>;
|
|
109
62
|
interface Config {
|
|
110
|
-
sdk:
|
|
63
|
+
sdk: ReactSdk;
|
|
111
64
|
}
|
|
112
|
-
declare const WorkspaceProvider: ({ sdk, children }: PropsWithChildren<
|
|
65
|
+
declare const WorkspaceProvider: ({ sdk, children, }: PropsWithChildren<{
|
|
66
|
+
sdk: SDK | ReactSdk;
|
|
67
|
+
}>) => React.JSX.Element;
|
|
113
68
|
|
|
114
|
-
declare function
|
|
69
|
+
declare function cacheKey(action: ActionRef | string, payload?: Record<string, unknown>): string;
|
|
115
70
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
71
|
+
interface ReadOptions {
|
|
72
|
+
/** When false, skip automatic fetch (default true). */
|
|
73
|
+
enabled?: boolean;
|
|
74
|
+
}
|
|
75
|
+
interface ReadResult<T = unknown> {
|
|
76
|
+
status: AsyncStatusType;
|
|
77
|
+
data: T | undefined;
|
|
78
|
+
error: Error | null | undefined;
|
|
79
|
+
refetch: () => Promise<T>;
|
|
80
|
+
}
|
|
81
|
+
declare function useRead<T = unknown>(action: ActionRef | string, payload?: Record<string, unknown>, options?: ReadOptions): ReadResult<T>;
|
|
121
82
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
83
|
+
interface SdkApi {
|
|
84
|
+
invoke: ReactSdk['invoke'];
|
|
85
|
+
read: typeof useRead;
|
|
86
|
+
invalidate: (key: string | string[]) => void;
|
|
87
|
+
cacheKey: typeof cacheKey;
|
|
88
|
+
sdk: ReactSdk;
|
|
89
|
+
}
|
|
90
|
+
declare function useSdk(): SdkApi;
|
|
91
|
+
|
|
92
|
+
/** Deterministic JSON for cache keys — sorted object keys, no Ramda. */
|
|
93
|
+
declare function stableSerialize(value: unknown): string;
|
|
128
94
|
|
|
129
|
-
export { AsyncStatus,
|
|
130
|
-
export type { AsyncStatusType, Config };
|
|
95
|
+
export { AsyncStatus, Context, ReactSdk, WorkspaceProvider, cacheKey, normalizeLocation, resolveActionId, stableSerialize, toActionRef, useRead, useSdk };
|
|
96
|
+
export type { ActionRef, AsyncStatusType, Config, ReadOptions, ReadResult, SdkApi };
|
package/build/types/Cache.d.ts
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { CacheEntry } from './cacheEntry';
|
|
2
3
|
export declare const CacheContext: React.Context<any>;
|
|
3
4
|
interface CacheConfig {
|
|
4
5
|
get: (key: string, state: unknown) => unknown;
|
|
5
6
|
set: (key: string, value: unknown, state: unknown) => unknown;
|
|
6
7
|
getInitialState?: () => unknown;
|
|
7
8
|
}
|
|
8
|
-
|
|
9
|
+
type Listener = () => void;
|
|
10
|
+
export interface ReadCacheStore {
|
|
11
|
+
getEntry: (key: string) => CacheEntry;
|
|
12
|
+
setEntry: (key: string, entry: CacheEntry | ((prev: CacheEntry) => CacheEntry)) => void;
|
|
13
|
+
invalidate: (key: string | string[]) => void;
|
|
14
|
+
subscribe: (listener: Listener) => () => void;
|
|
15
|
+
fetch: <T>(key: string, fetcher: () => Promise<T>) => Promise<T>;
|
|
16
|
+
}
|
|
17
|
+
export declare const createCache: ({ get: _get, set: _set, getInitialState, }: CacheConfig) => (props: any) => React.JSX.Element;
|
|
9
18
|
export declare const useCache: (cacheKey: string, defaultValue?: unknown) => {
|
|
10
19
|
data: any;
|
|
11
20
|
set: any;
|
|
12
21
|
};
|
|
22
|
+
export declare const useReadCacheStore: () => ReadCacheStore;
|
|
13
23
|
export {};
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import React, { PropsWithChildren } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { SDK } from '@ossy/sdk';
|
|
3
|
+
import { ReactSdk } from './react-sdk';
|
|
3
4
|
export declare const Context: React.Context<Config>;
|
|
4
5
|
export interface Config {
|
|
5
|
-
sdk:
|
|
6
|
+
sdk: ReactSdk;
|
|
6
7
|
}
|
|
7
|
-
export declare const WorkspaceProvider: ({ sdk, children }: PropsWithChildren<
|
|
8
|
+
export declare const WorkspaceProvider: ({ sdk, children, }: PropsWithChildren<{
|
|
9
|
+
sdk: SDK | ReactSdk;
|
|
10
|
+
}>) => React.JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Platform action POJO exported from feature `*.action.js` files. */
|
|
2
|
+
export type ActionRef = {
|
|
3
|
+
id: string;
|
|
4
|
+
access?: string;
|
|
5
|
+
};
|
|
6
|
+
/** Normalize dot aliases to slash ids (`booking.create` → `booking/create`). */
|
|
7
|
+
export declare function resolveActionId(action: ActionRef | string): string;
|
|
8
|
+
export declare function toActionRef(action: ActionRef | string): ActionRef;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
export * from './asyncStatus';
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './useWorkspaces';
|
|
6
|
-
export * from './useQuery';
|
|
7
|
-
export * from './useResource';
|
|
8
|
-
export * from './useResourceTemplate';
|
|
9
|
-
export * from './useResources';
|
|
2
|
+
export * from './normalizeLocation';
|
|
3
|
+
export * from './react-sdk';
|
|
4
|
+
export * from './action';
|
|
10
5
|
export * from './WorkspaceProvider';
|
|
11
6
|
export * from './useSdk';
|
|
12
|
-
export * from './
|
|
13
|
-
export * from './
|
|
7
|
+
export * from './useRead';
|
|
8
|
+
export * from './cacheKey';
|
|
9
|
+
export * from './stableSerialize';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { SDK, type SDKConfig } from '@ossy/sdk';
|
|
2
|
+
import { resolveActionId, type ActionRef } from './action';
|
|
3
|
+
/**
|
|
4
|
+
* Browser SDK for React apps. Dispatch platform actions with `invoke(action, payload)`.
|
|
5
|
+
*/
|
|
6
|
+
export declare class ReactSdk {
|
|
7
|
+
private sdk;
|
|
8
|
+
constructor(sdk: SDK);
|
|
9
|
+
get workspaceId(): string | undefined;
|
|
10
|
+
get authorization(): string | undefined;
|
|
11
|
+
updateConfig(config: SDKConfig): this;
|
|
12
|
+
invoke<TPayload extends Record<string, unknown> = Record<string, unknown>, TResult = unknown>(action: ActionRef | string, payload?: TPayload): Promise<TResult>;
|
|
13
|
+
/** @deprecated Use `invoke(action, payload)`. Kept for transitional resource uploads. */
|
|
14
|
+
get resources(): {
|
|
15
|
+
upload: ({ location, file }: {
|
|
16
|
+
location: string;
|
|
17
|
+
file: File;
|
|
18
|
+
}) => Promise<{
|
|
19
|
+
content: {
|
|
20
|
+
uploadUrl: string;
|
|
21
|
+
};
|
|
22
|
+
}>;
|
|
23
|
+
list: (query: {
|
|
24
|
+
location?: string;
|
|
25
|
+
}) => Promise<unknown>;
|
|
26
|
+
uploadNamedVersion: ({ id, name, file }: {
|
|
27
|
+
id: string;
|
|
28
|
+
name: string;
|
|
29
|
+
file: File;
|
|
30
|
+
}) => Promise<{
|
|
31
|
+
content: {
|
|
32
|
+
uploadUrl: string;
|
|
33
|
+
};
|
|
34
|
+
}>;
|
|
35
|
+
};
|
|
36
|
+
static from(sdk: SDK | ReactSdk): ReactSdk;
|
|
37
|
+
static of(config: SDKConfig): ReactSdk;
|
|
38
|
+
}
|
|
39
|
+
export { resolveActionId, type ActionRef };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type ActionRef } from './action';
|
|
2
|
+
import { type AsyncStatusType } from './asyncStatus';
|
|
3
|
+
import { cacheKey as buildCacheKey } from './cacheKey';
|
|
4
|
+
export interface ReadOptions {
|
|
5
|
+
/** When false, skip automatic fetch (default true). */
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export interface ReadResult<T = unknown> {
|
|
9
|
+
status: AsyncStatusType;
|
|
10
|
+
data: T | undefined;
|
|
11
|
+
error: Error | null | undefined;
|
|
12
|
+
refetch: () => Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
export declare function useRead<T = unknown>(action: ActionRef | string, payload?: Record<string, unknown>, options?: ReadOptions): ReadResult<T>;
|
|
15
|
+
export { buildCacheKey as cacheKey };
|
package/build/types/useSdk.d.ts
CHANGED
|
@@ -1 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { cacheKey } from './cacheKey';
|
|
2
|
+
import { useRead } from './useRead';
|
|
3
|
+
import type { ReactSdk } from './react-sdk';
|
|
4
|
+
export interface SdkApi {
|
|
5
|
+
invoke: ReactSdk['invoke'];
|
|
6
|
+
read: typeof useRead;
|
|
7
|
+
invalidate: (key: string | string[]) => void;
|
|
8
|
+
cacheKey: typeof cacheKey;
|
|
9
|
+
sdk: ReactSdk;
|
|
10
|
+
}
|
|
11
|
+
export declare function useSdk(): SdkApi;
|
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": "1.40.
|
|
4
|
+
"version": "1.40.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",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"/build",
|
|
53
53
|
"README.md"
|
|
54
54
|
],
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "c0ba5d90749690634e4dc2705178ff8d89dd3070"
|
|
56
56
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__spreadArray as e}from"../../../node_modules/tslib/tslib.es6.js";var n=function(n,r,i){var t=i.findIndex(function(e){return e[n]===r});return-1===t?i:e(e([],i.slice(0,t),!0),i.slice(t+1),!0)};export{n as removeBy};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var n=function(n,r,t){return t.map(function(t){return t[n]===r[n]?r:t})};export{n as replaceBy};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__spreadArray as t}from"../../../node_modules/tslib/tslib.es6.js";import{useCallback as n,useEffect as i}from"react";import{useCache as o}from"./Cache.js";import{AsyncStatus as e}from"./asyncStatus.js";import{useSdk as r}from"./useSdk.js";import{removeBy as a}from"./removeBy.js";var s=function(){var s=r(),u=o("apiTokens:status"),c=u.data,f=void 0===c?e.NotInitialized:c,d=u.set,m=o("apiTokens:data"),p=m.data,k=void 0===p?[]:p,l=m.set,v=n(function(n){return s.apiTokens.create(n).then(function(n){return l(function(i){return t(t([],i,!0),[n],!1)}),n})},[s]),T=n(function(t){return s.apiTokens.invalidate({id:t}).then(function(){return l(function(n){return a("id",t,n)})})},[s]),h=n(function(){d(e.Loading),s.apiTokens.list().then(function(t){l(t),d(e.Success)}).catch(function(){d(e.Error)})},[s]);return i(function(){f===e.NotInitialized&&h()},[f]),{status:f,tokens:k,createApiToken:v,invalidateApiToken:T}};export{s as useApiTokens};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useCallback as t,useEffect as n}from"react";import{useCache as i}from"./Cache.js";import{useSdk as r}from"./useSdk.js";var e={AuthenticationError:"AuthenticationError",NotInitialized:"NotInitialized",NotAuthenticated:"NotAuthenticated",Verifying:"Verifying",Authenticated:"Authenticated",VerifySignIn:"VerifySignIn"},u=function(){var u=r(),o=i("auth:status"),c=o.data,f=void 0===c?e.NotInitialized:c,a=o.set,h=t(function(t){return a(function(){return e.Verifying}),u.auth.signUp(t).then(function(){return a(e.VerifySignIn)}).catch(function(t){return a(e.AuthenticationError),Promise.reject(t)})},[u]),s=t(function(t){return a(function(){return e.Verifying}),u.auth.signIn({email:t}).then(function(){return a(e.VerifySignIn)}).catch(function(t){return a(e.AuthenticationError),Promise.reject(t)})},[u]),g=t(function(t){return a(function(){return e.Verifying}),u.auth.verifySignIn({token:t}).then(function(){return a(e.Authenticated)}).catch(function(t){return a(e.AuthenticationError),Promise.reject(t)})},[u]),d=t(function(t,n){return a(function(){return e.Verifying}),u.auth.verifyInvitation({workspaceId:t,token:n}).then(function(){return a(e.Authenticated)}).catch(function(t){return a(e.AuthenticationError),Promise.reject(t)})},[u]),A=t(function(){return u.auth.signOff().then(function(){return a(e.NotAuthenticated)})},[u]),y=t(function(){a(function(){return e.Verifying}),u.auth.getAuthenticatedUser().then(function(t){if(!t)return Promise.reject();a(function(){return e.Authenticated})}).catch(function(){a(function(){return e.NotAuthenticated})})},[u]);return n(function(){f===e.NotInitialized&&y()},[f,y]),{status:f,signUp:h,signIn:s,signOff:A,verifySignIn:g,verifyInvitation:d}};export{e as AuthenticationStatus,u as useAuthentication};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useMemo as r,useCallback as t,useEffect as n}from"react";import{useCache as e}from"./Cache.js";import{AsyncStatus as o}from"./asyncStatus.js";import{useSdk as a}from"./useSdk.js";var c=function(c){var s=a(),u=new URLSearchParams(c).toString(),i=r(function(){return"queries:".concat(u,":status")},[u]),f=r(function(){return"queries:".concat(u,":data")},[u]),d=r(function(){return"queries:".concat(u,":error")},[u]),l=e(i,o.NotInitialized),m=l.data,S=l.set,p=e(f,[]),g=p.data,h=p.set,j=e(d,null),q=j.data,E=j.set,v=t(function(r){S(o.Loading),E(null),s.resources.get(r).then(function(r){S(o.Success),h(r),E(null)}).catch(function(r){S(o.Error),E(r instanceof Error?r:new Error(String(r)))})},[s,S,h,E]);return n(function(){c&&m===o.NotInitialized&&v(c)},[c,m,v]),{status:m,resources:g,error:q,loadResources:v}};export{c as useQuery};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useMemo as e,useCallback as r,useEffect as n}from"react";import{useCache as t}from"./Cache.js";import{AsyncStatus as o}from"./asyncStatus.js";import{useResources as u}from"./useResources.js";import{useSdk as c}from"./useSdk.js";var s=function(s){c();var i=e(function(){return"resource:".concat(s,":status")},[s]),a=e(function(){return"resource:".concat(s,":data")},[s]),f=e(function(){return"resource:".concat(s,":error")},[s]),d=t(i),m=d.data,l=void 0===m?o.NotInitialized:m,R=d.set,p=t(a),v=p.data,h=void 0===v?{}:v,j=p.set,S=t(f,null),z=S.data,C=void 0===z?null:z,E=S.set,I=u(),N=I.loadResource,g=I.removeResource,k=I.updateResourceContent,w=I.renameResource,x=I.access,y=r(function(){R(o.Loading),j({}),E(null),N(s).then(function(e){R(o.Success),j(e),E(null)}).catch(function(e){R(o.Error),j({}),E(e instanceof Error?e:new Error(String(e)))})},[s,N,R,j,E]),L=r(function(){return g(s).then(function(){R(o.NotInitialized),j({})})},[s,g]),b=r(function(e){return k(s,e).then(function(e){return j(e)})},[s,k]),q=r(function(e){return w(s,e).then(function(e){return j(e)})},[s,w]),A=r(function(e){var r=e.access;return x({id:s,access:r}).then(function(e){return j(e),e})},[s,x]);return n(function(){s&&l===o.NotInitialized&&y()},[s,y]),{status:l,resource:h,error:C,loadResource:y,removeResource:L,updateResourceContent:b,renameResource:q,access:A}};export{s as useResource};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useWorkspace as r}from"./useWorkspace.js";var e=function(e){var o;return null===(o=r().workspace.resourceTemplates)||void 0===o?void 0:o.find(function(r){return r.id===e})};export{e as useResourceTemplate};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__spreadArray as n}from"../../../node_modules/tslib/tslib.es6.js";import{useMemo as r,useCallback as t,useEffect as e}from"react";import{useCache as o}from"./Cache.js";import{removeBy as u}from"./removeBy.js";import{replaceBy as c}from"./replaceBy.js";import{AsyncStatus as i}from"./asyncStatus.js";import{useSdk as s}from"./useSdk.js";function a(n){if(null==n||""===n)return"/";var r=n.replace(/^\/+|\/+$/g,"");return r?"/".concat(r,"/"):"/"}var f=function(f){var d=s(),l=r(function(){return a(f)},[f]),m=r(function(){return"resources:status:".concat(l)},[l]),v=r(function(){return"resources:data:".concat(l)},[l]),p=r(function(){return"resources:error:".concat(l)},[l]),h=o(m,i.NotInitialized),y=h.data,j=h.set,R=o(v,[]),g=R.data,S=R.set,C=o(p,null),D=C.data,E=C.set,b=t(function(n){var r=null==g?void 0:g.find(function(r){return r.id===n});return r?Promise.resolve(r):d.resources.get({id:n}).then(function(n){return S(function(r){return void 0===r&&(r=[]),a(n.location)===l?c("id",n,r):r}),n})},[d,g,S,l]),z=t(function(){j(i.Loading),E(null),d.resources.list({location:l}).then(function(n){j(i.Success),S(n),E(null)}).catch(function(n){j(i.Error),E(n instanceof Error?n:new Error(String(n)))})},[d,l,j,S,E]),B=t(function(r){return d.resources.create({type:r.type,location:a(r.location),name:r.name,content:r.content}).then(function(r){return S(function(t){return void 0===t&&(t=[]),a(r.location)===l?n(n([],t,!0),[r],!1):t}),r})},[d,S,l]),I=t(function(r,t){return d.resources.upload({location:a(r),file:t}).then(function(r){return S(function(t){return void 0===t&&(t=[]),a(r.location)===l?n(n([],t,!0),[r],!1):t}),r})},[d,S,l]),N=t(function(r){var t=r.location,e=r.name;return d.resources.createDirectory({type:"directory",location:a(t),name:e}).then(function(r){return S(function(t){return void 0===t&&(t=[]),a(r.location)===l?n(n([],t,!0),[r],!1):t}),r})},[d,S,l]),k=t(function(n){return d.resources.remove({id:n}).then(function(){S(function(r){return void 0===r&&(r=[]),u("id",n,r)})})},[d,S]),w=t(function(n,r){return d.resources.updateContent({id:n,content:r}).then(function(n){return S(function(r){return void 0===r&&(r=[]),c("id",n,r)}),n})},[d,S]),x=t(function(n,r){return d.resources.move({id:n,target:r}).then(function(r){return S(function(t){return void 0===t&&(t=[]),a(r.location)===l?c("id",r,t):u("id",n,t)}),r})},[d,S,l]),F=t(function(n,r){return d.resources.rename({id:n,name:r}).then(function(n){return S(function(r){return void 0===r&&(r=[]),c("id",n,r)}),n})},[d,S]),L=t(function(n){return d.resources.access(n).then(function(n){return S(function(r){return void 0===r&&(r=[]),c("id",n,r)}),n})},[S]);return e(function(){y===i.NotInitialized&&z()},[l,y,z]),{status:y,resources:g,error:D,loadResources:z,removeResource:k,createDocument:B,createDirectory:N,loadResource:b,updateResourceContent:w,moveResource:x,renameResource:F,uploadFile:I,access:L}};export{f as useResources};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useCallback as t,useEffect as r}from"react";import{useCache as n}from"./Cache.js";import{useSdk as e}from"./useSdk.js";import{AsyncStatus as u}from"./asyncStatus.js";var o=function(){var o=e(),i=n("user:status"),a=i.data,s=void 0===a?u.NotInitialized:a,c=i.set,f=n("user:data"),d=f.data,m=void 0===d?{}:d,p=f.set,h=t(function(t){return o.currentUser.update(t).then(function(t){return p(t),t})},[o]);return r(function(){s===u.NotInitialized&&(c(function(){return u.Loading}),o.currentUser.get().then(function(t){if(!t)return Promise.reject();p(t),c(function(){return u.Success})}).catch(function(){p({}),c(function(){return u.Error})}))},[s,o]),{status:s,user:m,update:h}};export{o as useUser};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{useCallback as r,useEffect as t}from"react";import{useCache as s}from"./Cache.js";import{AsyncStatus as a}from"./asyncStatus.js";import{useSdk as o}from"./useSdk.js";var n=function(){var n,u=o(),e=s("users"),i=e.data,l=void 0===i?{status:a.NotInitialized,data:[],error:null}:i,c=e.set,d=r(function(){c({status:a.Loading,data:[],error:null}),u.users.list().then(function(r){return c({data:r,status:a.Success,error:null})}).catch(function(r){return c({status:a.Error,data:[],error:r instanceof Error?r:new Error(String(r))})})},[u,c]);return t(function(){l.status===a.NotInitialized&&d()},[l.status,d]),{status:l.status,users:l.data,error:null!==(n=l.error)&&void 0!==n?n:null,load:d}};export{n as useUsers};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__assign as r,__spreadArray as t}from"../../../node_modules/tslib/tslib.es6.js";import{useCallback as o,useEffect as n}from"react";import{useCache as i}from"./Cache.js";import{AsyncStatus as e}from"./asyncStatus.js";import{useSdk as a}from"./useSdk.js";var s=function(s){var u,l=a(),d=i("workspace"),c=d.data,v=void 0===c?{status:e.NotInitialized,data:{},error:null}:c,p=d.set,f=o(function(){p({status:e.Loading,data:{},error:null}),((null==s?void 0:s.id)?l.workspaces.get({id:s.id}):l.workspaces.current()).then(function(r){return p({data:r,status:e.Success,error:null})}).catch(function(r){return p({status:e.Error,data:{},error:r instanceof Error?r:new Error(String(r))})})},[l,null==s?void 0:s.id]),k=o(function(o){return l.workspaces.createApiToken({description:o}).then(function(n){var i=n.id,a=n.token;return p(function(n){var a,s,u,l,d;return{status:null!==(a=null==n?void 0:n.status)&&void 0!==a?a:e.NotInitialized,data:r(r({},null!==(s=null==n?void 0:n.data)&&void 0!==s?s:{}),{apiTokens:t(t([],null!==(l=null===(u=null==n?void 0:n.data)||void 0===u?void 0:u.apiTokens)&&void 0!==l?l:[],!0),[{id:i,description:o}],!1)}),error:null!==(d=null==n?void 0:n.error)&&void 0!==d?d:null}}),a})},[l,p]),m=o(function(r){return l.workspaces.inviteUser({email:r})},[l]);return n(function(){v.status===e.NotInitialized&&f()},[v.status,f]),{status:v.status,workspace:v.data,error:null!==(u=v.error)&&void 0!==u?u:null,loadWorkspace:f,createApiToken:k,inviteUser:m}};export{s as useWorkspace};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{__spreadArray as t}from"../../../node_modules/tslib/tslib.es6.js";import{useCallback as r,useEffect as o,useRef as a}from"react";import{useCache as n}from"./Cache.js";import{AsyncStatus as e}from"./asyncStatus.js";import{useSdk as s}from"./useSdk.js";import{AuthenticationStatus as u}from"./useAuthentication.js";var i=function(){var i,l=s(),c=n("workspaces"),d=c.set,f=c.data,m=void 0===f?{status:e.NotInitialized,data:[],error:null}:f,p=n("auth:status").data,v=r(function(){d({status:e.Loading,data:[],error:null}),l.workspaces.list().then(function(t){return d({status:e.Success,data:t,error:null})}).catch(function(t){return d({status:e.Error,data:[],error:t instanceof Error?t:new Error(String(t))})})},[l,d]),h=r(function(r){return l.workspaces.create({name:r}).then(function(r){return d(function(o){var a,n,s;return{status:null!==(a=null==o?void 0:o.status)&&void 0!==a?a:e.NotInitialized,data:t(t([],null!==(n=null==o?void 0:o.data)&&void 0!==n?n:[],!0),[r],!1),error:null!==(s=null==o?void 0:o.error)&&void 0!==s?s:null}}),r})},[l,d]);o(function(){m.status===e.NotInitialized&&v()},[m,v]);var k=a(void 0);return o(function(){p===u.Authenticated&&k.current!==u.Authenticated&&v(),k.current=p},[p,v]),{status:m.status,workspaces:m.data,error:null!==(i=m.error)&&void 0!==i?i:null,loadWorkspaces:v,createWorkspace:h}};export{i as useWorkspaces};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const removeBy: <T extends Record<string, unknown>>(prop: string, propValue: unknown, list: T[]) => T[];
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const replaceBy: <T extends Record<string, unknown>>(prop: string, item: T, list: T[]) => T[];
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export declare const AuthenticationStatus: {
|
|
2
|
-
AuthenticationError: string;
|
|
3
|
-
NotInitialized: string;
|
|
4
|
-
NotAuthenticated: string;
|
|
5
|
-
Verifying: string;
|
|
6
|
-
Authenticated: string;
|
|
7
|
-
VerifySignIn: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const useAuthentication: () => {
|
|
10
|
-
status: any;
|
|
11
|
-
signUp: (payload: {
|
|
12
|
-
email: string;
|
|
13
|
-
firstName: string;
|
|
14
|
-
lastName: string;
|
|
15
|
-
}) => Promise<any>;
|
|
16
|
-
signIn: (email: any) => Promise<any>;
|
|
17
|
-
signOff: () => Promise<any>;
|
|
18
|
-
verifySignIn: (token: string) => Promise<any>;
|
|
19
|
-
verifyInvitation: (workspaceId: string, token: string) => Promise<any>;
|
|
20
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export declare const useResource: (id: string) => {
|
|
2
|
-
status: any;
|
|
3
|
-
resource: any;
|
|
4
|
-
error: any;
|
|
5
|
-
loadResource: () => void;
|
|
6
|
-
removeResource: () => Promise<void>;
|
|
7
|
-
updateResourceContent: (content: any) => Promise<any>;
|
|
8
|
-
renameResource: (name: string) => Promise<any>;
|
|
9
|
-
access: ({ access }: {
|
|
10
|
-
access: "restricted" | "public";
|
|
11
|
-
}) => Promise<any>;
|
|
12
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useResourceTemplate: (id: string) => any;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export declare const useResources: (location?: string) => {
|
|
2
|
-
status: any;
|
|
3
|
-
resources: any;
|
|
4
|
-
error: any;
|
|
5
|
-
loadResources: () => void;
|
|
6
|
-
removeResource: (id: string) => Promise<void>;
|
|
7
|
-
createDocument: (document: any) => Promise<any>;
|
|
8
|
-
createDirectory: ({ location, name }: {
|
|
9
|
-
location: string;
|
|
10
|
-
name: string;
|
|
11
|
-
}) => Promise<any>;
|
|
12
|
-
loadResource: (id: string) => Promise<any>;
|
|
13
|
-
updateResourceContent: (id: string, content: any) => Promise<any>;
|
|
14
|
-
moveResource: (id: string, target: string) => Promise<any>;
|
|
15
|
-
renameResource: (id: string, name: string) => Promise<any>;
|
|
16
|
-
uploadFile: (location: string, file: File) => Promise<any>;
|
|
17
|
-
access: (params: {
|
|
18
|
-
id: string;
|
|
19
|
-
access: "restricted" | "public";
|
|
20
|
-
}) => Promise<any>;
|
|
21
|
-
};
|
package/build/types/useUser.d.ts
DELETED