@ossy/sdk-react 0.0.1 → 0.0.10
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/CHANGELOG.md +72 -0
- package/LICENSE +21 -0
- package/build/index.cjs.js +1 -1
- package/build/index.esm.js +1 -1
- package/package.json +14 -10
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 0.0.10 (2025-10-25)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 0.0.9 (2025-10-25)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 0.0.8 (2025-10-25)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 0.0.7 (2025-10-25)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## 0.0.6 (2025-10-25)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## 0.0.5 (2025-10-25)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## 0.0.4 (2025-10-25)
|
|
55
|
+
|
|
56
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
## 0.0.3 (2025-10-25)
|
|
63
|
+
|
|
64
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
## 0.0.2 (2025-10-25)
|
|
71
|
+
|
|
72
|
+
**Note:** Version bump only for package @ossy/sdk-react
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Ossy
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/build/index.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(t);const n={NotInitialized:"NotInitialized",Loading:"Loading",Success:"Success",Error:"Error"};function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},a.apply(null,arguments)}const u=t.createContext(),s="SET",o=(e,r)=>{const{get:n,set:a}=t.useContext(u);return{data:(()=>{const t=n(e);return null==t?r:t})(),set:a(e)}};function c(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function i(t){return function e(r){return 0===arguments.length||c(r)?e:t.apply(this,arguments)}}function l(t){return function e(r,n){switch(arguments.length){case 0:return e;case 1:return c(r)?e:i((function(e){return t(r,e)}));default:return c(r)&&c(n)?e:c(r)?i((function(e){return t(e,n)})):c(n)?i((function(e){return t(r,e)})):t(r,n)}}}function f(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,r){return e.apply(this,arguments)};case 3:return function(t,r,n){return e.apply(this,arguments)};case 4:return function(t,r,n,a){return e.apply(this,arguments)};case 5:return function(t,r,n,a,u){return e.apply(this,arguments)};case 6:return function(t,r,n,a,u,s){return e.apply(this,arguments)};case 7:return function(t,r,n,a,u,s,o){return e.apply(this,arguments)};case 8:return function(t,r,n,a,u,s,o,c){return e.apply(this,arguments)};case 9:return function(t,r,n,a,u,s,o,c,i){return e.apply(this,arguments)};case 10:return function(t,r,n,a,u,s,o,c,i,l){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function d(t,e,r){return function(){for(var n=[],a=0,u=t,s=0;s<e.length||a<arguments.length;){var o;s<e.length&&(!c(e[s])||a>=arguments.length)?o=e[s]:(o=arguments[a],a+=1),n[s]=o,c(o)||(u-=1),s+=1}return u<=0?r.apply(this,n):f(u,d(t,n,r))}}var p=l((function(t,e){return 1===t?i(e):f(t,d(t,[],e))}));function h(t){return function e(r,n,a){switch(arguments.length){case 0:return e;case 1:return c(r)?e:l((function(e,n){return t(r,e,n)}));case 2:return c(r)&&c(n)?e:c(r)?l((function(e,r){return t(e,n,r)})):c(n)?l((function(e,n){return t(r,e,n)})):i((function(e){return t(r,n,e)}));default:return c(r)&&c(n)&&c(a)?e:c(r)&&c(n)?l((function(e,r){return t(e,r,a)})):c(r)&&c(a)?l((function(e,r){return t(e,n,r)})):c(n)&&c(a)?l((function(e,n){return t(r,e,n)})):c(r)?i((function(e){return t(e,n,a)})):c(n)?i((function(e){return t(r,e,a)})):c(a)?i((function(e){return t(r,n,e)})):t(r,n,a)}}}var y=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)};function g(t,e,r){return function(){if(0===arguments.length)return r();var n=Array.prototype.slice.call(arguments,0),a=n.pop();if(!y(a)){for(var u=0;u<t.length;){if("function"==typeof a[t[u]])return a[t[u]].apply(a,n);u+=1}if(function(t){return null!=t&&"function"==typeof t["@@transducer/step"]}(a))return e.apply(null,n)(a)}return r.apply(this,arguments)}}var k=function(){return this.xf["@@transducer/init"]()},b=function(t){return this.xf["@@transducer/result"](t)};function v(t){return"[object String]"===Object.prototype.toString.call(t)}var m=i((function(t){return!!y(t)||!!t&&("object"==typeof t&&(!v(t)&&(1===t.nodeType?!!t.length:0===t.length||t.length>0&&(t.hasOwnProperty(0)&&t.hasOwnProperty(t.length-1)))))})),A=function(){function t(t){this.f=t}return t.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},t.prototype["@@transducer/result"]=function(t){return t},t.prototype["@@transducer/step"]=function(t,e){return this.f(t,e)},t}();var I=l((function(t,e){return f(t.length,(function(){return t.apply(e,arguments)}))}));function C(t,e,r){for(var n=r.next();!n.done;){if((e=t["@@transducer/step"](e,n.value))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}n=r.next()}return t["@@transducer/result"](e)}function w(t,e,r,n){return t["@@transducer/result"](r[n](I(t["@@transducer/step"],t),e))}var E="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";function x(t,e,r){if("function"==typeof t&&(t=function(t){return new A(t)}(t)),m(r))return function(t,e,r){for(var n=0,a=r.length;n<a;){if((e=t["@@transducer/step"](e,r[n]))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}n+=1}return t["@@transducer/result"](e)}(t,e,r);if("function"==typeof r["fantasy-land/reduce"])return w(t,e,r,"fantasy-land/reduce");if(null!=r[E])return C(t,e,r[E]());if("function"==typeof r.next)return C(t,e,r);if("function"==typeof r.reduce)return w(t,e,r,"reduce");throw new TypeError("reduce: list must be array or iterable")}var S=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=k,t.prototype["@@transducer/result"]=b,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},t}(),j=l((function(t,e){return new S(t,e)}));function N(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var O=Object.prototype.toString,z=function(){return"[object Arguments]"===O.call(arguments)?function(t){return"[object Arguments]"===O.call(t)}:function(t){return N("callee",t)}}(),P=!{toString:null}.propertyIsEnumerable("toString"),R=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],T=function(){return arguments.propertyIsEnumerable("length")}(),q=function(t,e){for(var r=0;r<t.length;){if(t[r]===e)return!0;r+=1}return!1},L="function"!=typeof Object.keys||T?i((function(t){if(Object(t)!==t)return[];var e,r,n=[],a=T&&z(t);for(e in t)!N(e,t)||a&&"length"===e||(n[n.length]=e);if(P)for(r=R.length-1;r>=0;)N(e=R[r],t)&&!q(n,e)&&(n[n.length]=e),r-=1;return n})):i((function(t){return Object(t)!==t?[]:Object.keys(t)})),U=l(g(["fantasy-land/map","map"],j,(function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return p(e.length,(function(){return t.call(this,e.apply(this,arguments))}));case"[object Object]":return x((function(r,n){return r[n]=t(e[n]),r}),{},L(e));default:return function(t,e){for(var r=0,n=e.length,a=Array(n);r<n;)a[r]=t(e[r]),r+=1;return a}(t,e)}}))),M=Number.isInteger||function(t){return(t|0)===t},V=l((function(t,e){var r=t<0?e.length+t:t;return v(e)?e.charAt(r):e[r]})),W=l((function(t,e){return t.map((function(t){for(var r,n=e,a=0;a<t.length;){if(null==n)return;r=t[a],n=M(r)?V(r,n):n[r],a+=1}return n}))})),D=l((function(t,e){return W([t],e)[0]})),F=i((function(t){return function(){return t}})),B=h((function(t,e,r){var n={};for(var a in r)n[a]=r[a];return n[t]=e,n})),Q=i((function(t){return null==t})),_=h((function t(e,r,n){if(0===e.length)return r;var a=e[0];if(e.length>1){var u=!Q(n)&&N(a,n)?n[a]:M(e[1])?[]:{};r=t(Array.prototype.slice.call(e,1),r,u)}if(M(a)&&y(n)){var s=[].concat(n);return s[a]=r,s}return B(a,r,n)})),X=_,G=i((function(t){return p(t.length,t)})),H=i((function(t){return null===t?"Null":void 0===t?"Undefined":Object.prototype.toString.call(t).slice(8,-1)}));function J(t){for(var e,r=[];!(e=t.next()).done;)r.push(e.value);return r}function K(t,e,r){for(var n=0,a=r.length;n<a;){if(t(e,r[n]))return!0;n+=1}return!1}var Y="function"==typeof Object.is?Object.is:function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};function Z(t,e,r,n){var a=J(t);function u(t,e){return $(t,e,r.slice(),n.slice())}return!K((function(t,e){return!K(u,e,t)}),J(e),a)}function $(t,e,r,n){if(Y(t,e))return!0;var a,u,s=H(t);if(s!==H(e))return!1;if(null==t||null==e)return!1;if("function"==typeof t["fantasy-land/equals"]||"function"==typeof e["fantasy-land/equals"])return"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e)&&"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t);if("function"==typeof t.equals||"function"==typeof e.equals)return"function"==typeof t.equals&&t.equals(e)&&"function"==typeof e.equals&&e.equals(t);switch(s){case"Arguments":case"Array":case"Object":if("function"==typeof t.constructor&&"Promise"===(a=t.constructor,null==(u=String(a).match(/^function (\w*)/))?"":u[1]))return t===e;break;case"Boolean":case"Number":case"String":if(typeof t!=typeof e||!Y(t.valueOf(),e.valueOf()))return!1;break;case"Date":if(!Y(t.valueOf(),e.valueOf()))return!1;break;case"Error":return t.name===e.name&&t.message===e.message;case"RegExp":if(t.source!==e.source||t.global!==e.global||t.ignoreCase!==e.ignoreCase||t.multiline!==e.multiline||t.sticky!==e.sticky||t.unicode!==e.unicode)return!1}for(var o=r.length-1;o>=0;){if(r[o]===t)return n[o]===e;o-=1}switch(s){case"Map":return t.size===e.size&&Z(t.entries(),e.entries(),r.concat([t]),n.concat([e]));case"Set":return t.size===e.size&&Z(t.values(),e.values(),r.concat([t]),n.concat([e]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var c=L(t);if(c.length!==L(e).length)return!1;var i=r.concat([t]),l=n.concat([e]);for(o=c.length-1;o>=0;){var f=c[o];if(!N(f,e)||!$(e[f],t[f],i,l))return!1;o-=1}return!0}var tt=l((function(t,e){return $(t,e,[],[])})),et=h((function(t,e,r){var n=Array.prototype.slice.call(r,0);return n.splice(t,e),n})),rt=function(){function t(t,e){this.xf=e,this.f=t,this.idx=-1,this.found=!1}return t.prototype["@@transducer/init"]=k,t.prototype["@@transducer/result"]=function(t){return this.found||(t=this.xf["@@transducer/step"](t,-1)),this.xf["@@transducer/result"](t)},t.prototype["@@transducer/step"]=function(t,e){var r;return this.idx+=1,this.f(e)&&(this.found=!0,t=(r=this.xf["@@transducer/step"](t,this.idx))&&r["@@transducer/reduced"]?r:{"@@transducer/value":r,"@@transducer/reduced":!0}),t},t}(),nt=l(g([],l((function(t,e){return new rt(t,e)})),(function(t,e){for(var r=0,n=e.length;r<n;){if(t(e[r]))return r;r+=1}return-1}))),at=l((function(t,e){return function(r){return function(n){return U((function(t){return e(t,n)}),r(t(n)))}}})),ut=i((function(t){return at(D(t),X(t))})),st=function(t){return{value:t,map:function(e){return st(e(t))}}},ot=h((function(t,e,r){return t((function(t){return st(e(t))}))(r).value})),ct=ot,it=h((function(t,e,r){return tt(e,r[t])})),lt=h((function(t,e,r){return ct(t,F(e),r)})),ft=lt;const dt=t.createContext({}),pt=(({get:e,set:n})=>o=>{const[c,i]=t.useReducer((({set:t,get:e})=>(r={},n)=>{if(n.type===s){let a;if("function"==typeof n.data){const t=e(n.cachePath,r);a=n.data(t)}else a=n.data;return t(n.cachePath,a,r)}return{...r}})({set:n,get:e}),{}),l=t.useCallback((t=>e=>{i({type:s,cachePath:t,data:e})}),[i]),f=t.useCallback((t=>e(t,c)),[c,e]);return r.default.createElement(u.Provider,a({value:{get:f,set:l}},o))})({get:D,set:(t,e,r)=>ft(ut(t),e,r)});function ht(){return t.useContext(dt).sdk}const yt=G(((t,e,r)=>{const n=nt(it(t,e),r);return-1===n?r:et(n,1,r)})),gt=["apiTokens","status"],kt=["apiTokens","data"],bt={AuthenticationError:"AuthenticationError",NotInitialized:"NotInitialized",NotAuthenticated:"NotAuthenticated",Verifying:"Verifying",Authenticated:"Authenticated",VerifySignIn:"VerifySignIn"},vt=["auth","status"],mt=()=>{const e=ht(),r=e.workspaceId,a=t.useMemo((()=>["workspace",r]),[r]),{data:u={status:n.NotInitialized,data:{}},set:s}=o(a),c=t.useCallback((()=>{s({status:n.Loading,data:{}}),e.workspaces.byId(r).then((t=>s({data:t,status:n.Success}))).catch((()=>s({status:n.Error,data:{}})))}),[e,r]),i=t.useCallback((t=>e.workspaces.createApiToken(r,t).then((({id:e,token:r})=>(s({status:workspaces.status,data:{...u,apiTokens:[...u.apiTokens,{id:e,description:t}]}}),r)))),[e]),l=t.useCallback((t=>e.workspaces.inviteUser(r,t)),[e]);return t.useEffect((()=>{r&&u.status===n.NotInitialized&&c()}),[r,u]),{status:u.status,workspace:u.data,loadWorkspace:c,createApiToken:i,inviteUser:l}},At=["workspaces"],It=G(((t,e,r)=>U((r=>r[t]===e[t]?e:r),r))),Ct=e=>{const r=ht(),a=r.workspaceId,u=t.useMemo((()=>["resources",a,"status",e]),[a,e]),s=t.useMemo((()=>["resources",a,"data"]),[a]),{data:c,set:i}=o(u,n.NotInitialized),{data:l,set:f}=o(s,[]),d=t.useMemo((()=>l.filter((t=>t.location===e))),[l,e]),p=t.useCallback((t=>{const e=l.find((e=>e.id===t));return e?Promise.resolve(e):r.resources.byId(t).then((t=>(f(((e=[])=>It("id",t,e))),t)))}),[r,l,f]),h=t.useCallback((()=>{i(n.Loading),r.resources.byLocation(e).then((t=>{i(n.Success),f(((e=[])=>{const r=t.map((t=>t.id)),n=e.filter((t=>!r.includes(t.id)));return[...t,...n]}))})).catch((()=>{i(n.Error)}))}),[r,e,i,f]),y=t.useCallback((t=>r.resources.create({type:t.type,location:t.location,name:t.name,content:t.content}).then((t=>(f(((e=[])=>[...e,t])),t)))),[r,f]),g=t.useCallback(((t,e)=>r.resources.upload({location:t,file:e}).then((t=>(f(((e=[])=>[...e,t])),t)))),[r,f]),k=t.useCallback((({location:t,name:e})=>r.resources.createDirectory({location:t,name:e}).then((t=>(f(((e=[])=>[...e,t])),t)))),[r,f]),b=t.useCallback((t=>r.resources.remove(t).then((()=>f(((e=[])=>yt("id",t,e)))))),[r,f]),v=t.useCallback(((t,e)=>r.resources.updateContent(t,e).then((t=>(f(((e=[])=>It("id",t,e))),t)))),[r,a,f]),m=t.useCallback(((t,e)=>r.resources.move(t,e).then((t=>(f(((e=[])=>It("id",t,e))),t)))),[r,a,f]),A=t.useCallback(((t,e)=>r.resources.rename(t,e).then((t=>(f(((e=[])=>It("id",t,e))),t)))),[r,a,f]);return t.useEffect((()=>{a&&e&&c===n.NotInitialized&&h()}),[a,e,c]),{status:c,resources:d,removeResource:b,createDocument:y,createDirectory:k,loadResource:p,updateResourceContent:v,moveResource:m,renameResource:A,uploadFile:g}},wt=["user","status"],Et=["user","data"];exports.AsyncStatus=n,exports.AuthenticationStatus=bt,exports.Context=dt,exports.WorkspaceProvider=({sdk:t,children:e})=>r.default.createElement(pt,null,r.default.createElement(dt.Provider,{value:{sdk:t}},e)),exports.useApiTokens=()=>{const e=ht(),{data:r=n.NotInitialized,set:a}=o(gt),{data:u=[],set:s}=o(kt),c=t.useCallback((t=>e.apiTokens.create(t).then((t=>(s((e=>[...e,t])),t)))),[e]),i=t.useCallback((t=>e.apiTokens.invalidate(t).then((()=>s((e=>yt("id",t,e)))))),[e]),l=t.useCallback((()=>{a(n.Loading),e.apiTokens.getAll().then((t=>{s(t),a(n.Success)})).catch((()=>{a(n.Error)}))}),[e]);return t.useEffect((()=>{r===n.NotInitialized&&l()}),[r]),{status:r,tokens:u,createApiToken:c,invalidateApiToken:i}},exports.useAuthentication=()=>{const e=ht(),{data:r=bt.NotInitialized,set:n}=o(vt),a=t.useCallback((t=>(n((()=>bt.Verifying)),e.auth.signUp(t).then((()=>n(bt.VerifySignIn))).catch((t=>(n(bt.AuthenticationError),Promise.reject(t)))))),[e]),u=t.useCallback((t=>(n((()=>bt.Verifying)),e.auth.signIn(t).then((()=>n(bt.VerifySignIn))).catch((t=>(n(bt.AuthenticationError),Promise.reject(t)))))),[e]),s=t.useCallback((t=>(n((()=>bt.Verifying)),e.auth.verifySignIn(t).then((()=>n(bt.Authenticated))).catch((t=>(n(bt.AuthenticationError),Promise.reject(t)))))),[e]),c=t.useCallback(((t,r)=>(n((()=>bt.Verifying)),e.auth.verifyInvitation(t,r).then((()=>n(bt.Authenticated))).catch((t=>(n(bt.AuthenticationError),Promise.reject(t)))))),[e]),i=t.useCallback((()=>e.auth.signOff().then((()=>n(bt.NotAuthenticated)))),[e]);return t.useEffect((()=>{r===bt.NotInitialized&&(n((()=>bt.Verifying)),e.auth.getAuthenticatedUser().then((t=>{if(!t)return Promise.reject();n((()=>bt.Authenticated))})).catch((()=>{n((()=>bt.NotAuthenticated))})))}),[r]),{status:r,signUp:a,signIn:u,signOff:i,verifySignIn:s,verifyInvitation:c}},exports.useQuery=e=>{const r=ht(),a=r.workspaceId,u=new URLSearchParams(e).toString();console.log("useQuery",e,u);const s=t.useMemo((()=>[a,"queries",u,"status"]),[a,u]),c=t.useMemo((()=>[a,"queries",u,"data"]),[a,u]),{data:i,set:l}=o(s,n.NotInitialized),{data:f,set:d}=o(c,[]),p=t.useCallback((t=>{l(n.Loading),r.resources.get(t).then((t=>{l(n.Success),d(t)})).catch((()=>{l(n.Error)}))}),[r]);return t.useEffect((()=>{console.log("useQuery effect",a,e,i),a&&e&&i===n.NotInitialized&&p(e)}),[a,e,i]),{status:i,resources:f}},exports.useResource=e=>{const r=ht().workspaceId,a=t.useMemo((()=>["resource",r,e,"status"]),[e,r]),u=t.useMemo((()=>["resource",r,e,"data"]),[e,r]),{data:s=n.NotInitialized,set:c}=o(a),{data:i={},set:l}=o(u),{loadResource:f,removeResource:d,updateResourceContent:p,renameResource:h}=Ct(),y=t.useCallback((()=>{c(n.Loading),l({}),f(e).then((t=>{c(n.Success),l(t)})).catch((()=>{c(n.Error),l({})}))}),[e,f]),g=t.useCallback((()=>d(e).then((()=>{c(n.NotInitialized),l({})}))),[e,d]),k=t.useCallback((t=>p(e,t).then((t=>l(t)))),[e,p]),b=t.useCallback((t=>h(e,t).then((t=>l(t)))),[e,h]);return t.useEffect((()=>{r&&e&&s===n.NotInitialized&&y()}),[r,e,y]),{status:s,resource:i,loadResource:y,removeResource:g,updateResourceContent:k,renameResource:b}},exports.useResourceTemplate=t=>{const{workspace:e}=mt();return e.resourceTemplates.find((e=>e.id===t))},exports.useResources=Ct,exports.useSdk=ht,exports.useUser=()=>{const e=ht(),{data:r=n.NotInitialized,set:a}=o(wt),{data:u={},set:s}=o(Et),c=t.useCallback((t=>e.user.update(t).then((t=>(s(t),t)))),[e]);return t.useEffect((()=>{r===n.NotInitialized&&(a((()=>n.Loading)),e.user.details().then((t=>{if(!t)return Promise.reject();s(t),a((()=>n.Success))})).catch((()=>{s({}),a((()=>n.Error))})))}),[r]),{status:r,user:u,update:c}},exports.useUsers=()=>{const e=ht(),r=e.workspaceId,a=t.useMemo((()=>["workspace",r,"users"]),[r]),{data:u={status:n.NotInitialized,data:[]},set:s}=o(a),c=t.useCallback((()=>{s({status:n.Loading,data:[]}),e.workspaces.users().then((t=>s({data:t,status:n.Success}))).catch((()=>s({status:n.Error,data:[]})))}),[e]);return t.useEffect((()=>{r&&u.status===n.NotInitialized&&c()}),[r,u]),{status:u.status,users:u.data,load:c}},exports.useWorkspace=mt,exports.useWorkspaces=()=>{const e=ht(),{set:r,data:a={status:n.NotInitialized,data:[]}}=o(At),u=t.useCallback((()=>{r({status:n.Loading,data:[]}),e.workspaces.getAll().then((t=>r({status:n.Success,data:t}))).catch((()=>r({status:n.Error,data:[]})))}),[e]),s=t.useCallback((t=>e.workspaces.create(t).then((t=>(r({status:a.status,data:[...a.data,t]}),t)))),[e]);return t.useEffect((()=>{a.status===n.NotInitialized&&u()}),[a,u]),{status:a.status,workspaces:a.data,loadWorkspaces:u,createWorkspace:s}};
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react");function e(t){return t&&"object"==typeof t&&"default"in t?t:{default:t}}var r=e(t);const n={NotInitialized:"NotInitialized",Loading:"Loading",Success:"Success",Error:"Error"};function a(){return a=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},a.apply(null,arguments)}const u=t.createContext(),s="SET",c=(e,r)=>{const{get:n,set:a}=t.useContext(u);return{data:(()=>{const t=n(e);return null==t?r:t})(),set:a(e)}};function o(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function i(t){return function e(r){return 0===arguments.length||o(r)?e:t.apply(this,arguments)}}function l(t){return function e(r,n){switch(arguments.length){case 0:return e;case 1:return o(r)?e:i(function(e){return t(r,e)});default:return o(r)&&o(n)?e:o(r)?i(function(e){return t(e,n)}):o(n)?i(function(e){return t(r,e)}):t(r,n)}}}function f(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,r){return e.apply(this,arguments)};case 3:return function(t,r,n){return e.apply(this,arguments)};case 4:return function(t,r,n,a){return e.apply(this,arguments)};case 5:return function(t,r,n,a,u){return e.apply(this,arguments)};case 6:return function(t,r,n,a,u,s){return e.apply(this,arguments)};case 7:return function(t,r,n,a,u,s,c){return e.apply(this,arguments)};case 8:return function(t,r,n,a,u,s,c,o){return e.apply(this,arguments)};case 9:return function(t,r,n,a,u,s,c,o,i){return e.apply(this,arguments)};case 10:return function(t,r,n,a,u,s,c,o,i,l){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function d(t,e,r){return function(){for(var n=[],a=0,u=t,s=0,c=!1;s<e.length||a<arguments.length;){var i;s<e.length&&(!o(e[s])||a>=arguments.length)?i=e[s]:(i=arguments[a],a+=1),n[s]=i,o(i)?c=!0:u-=1,s+=1}return!c&&u<=0?r.apply(this,n):f(Math.max(0,u),d(t,n,r))}}var p=l(function(t,e){return 1===t?i(e):f(t,d(t,[],e))});function h(t){return function e(r,n,a){switch(arguments.length){case 0:return e;case 1:return o(r)?e:l(function(e,n){return t(r,e,n)});case 2:return o(r)&&o(n)?e:o(r)?l(function(e,r){return t(e,n,r)}):o(n)?l(function(e,n){return t(r,e,n)}):i(function(e){return t(r,n,e)});default:return o(r)&&o(n)&&o(a)?e:o(r)&&o(n)?l(function(e,r){return t(e,r,a)}):o(r)&&o(a)?l(function(e,r){return t(e,n,r)}):o(n)&&o(a)?l(function(e,n){return t(r,e,n)}):o(r)?i(function(e){return t(e,n,a)}):o(n)?i(function(e){return t(r,e,a)}):o(a)?i(function(e){return t(r,n,e)}):t(r,n,a)}}}var y=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)};function g(t,e,r){return function(){if(0===arguments.length)return r();var n=arguments[arguments.length-1];if(!y(n)){for(var a=0;a<t.length;){if("function"==typeof n[t[a]])return n[t[a]].apply(n,Array.prototype.slice.call(arguments,0,-1));a+=1}if(function(t){return null!=t&&"function"==typeof t["@@transducer/step"]}(n))return e.apply(null,Array.prototype.slice.call(arguments,0,-1))(n)}return r.apply(this,arguments)}}var k=function(){return this.xf["@@transducer/init"]()},v=function(t){return this.xf["@@transducer/result"](t)};function b(t){for(var e,r=[];!(e=t.next()).done;)r.push(e.value);return r}function m(t,e,r){for(var n=0,a=r.length;n<a;){if(t(e,r[n]))return!0;n+=1}return!1}function A(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var I="function"==typeof Object.is?Object.is:function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e},C=Object.prototype.toString,E=function(){return"[object Arguments]"===C.call(arguments)?function(t){return"[object Arguments]"===C.call(t)}:function(t){return A("callee",t)}}(),x=!{toString:null}.propertyIsEnumerable("toString"),S=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],w=function(){return arguments.propertyIsEnumerable("length")}(),j=function(t,e){for(var r=0;r<t.length;){if(t[r]===e)return!0;r+=1}return!1},N="function"!=typeof Object.keys||w?i(function(t){if(Object(t)!==t)return[];var e,r,n=[],a=w&&E(t);for(e in t)!A(e,t)||a&&"length"===e||(n[n.length]=e);if(x)for(r=S.length-1;r>=0;)A(e=S[r],t)&&!j(n,e)&&(n[n.length]=e),r-=1;return n}):i(function(t){return Object(t)!==t?[]:Object.keys(t)}),O=N,z=i(function(t){return null===t?"Null":void 0===t?"Undefined":Object.prototype.toString.call(t).slice(8,-1)});function P(t,e,r,n){var a=b(t);function u(t,e){return R(t,e,r.slice(),n.slice())}return!m(function(t,e){return!m(u,e,t)},b(e),a)}function R(t,e,r,n){if(I(t,e))return!0;var a,u,s=z(t);if(s!==z(e))return!1;if("function"==typeof t["fantasy-land/equals"]||"function"==typeof e["fantasy-land/equals"])return"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e)&&"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t);if("function"==typeof t.equals||"function"==typeof e.equals)return"function"==typeof t.equals&&t.equals(e)&&"function"==typeof e.equals&&e.equals(t);switch(s){case"Arguments":case"Array":case"Object":if("function"==typeof t.constructor&&"Promise"===(a=t.constructor,null==(u=String(a).match(/^function (\w*)/))?"":u[1]))return t===e;break;case"Boolean":case"Number":case"String":if(typeof t!=typeof e||!I(t.valueOf(),e.valueOf()))return!1;break;case"Date":if(!I(t.valueOf(),e.valueOf()))return!1;break;case"Error":return t.name===e.name&&t.message===e.message;case"RegExp":if(t.source!==e.source||t.global!==e.global||t.ignoreCase!==e.ignoreCase||t.multiline!==e.multiline||t.sticky!==e.sticky||t.unicode!==e.unicode)return!1}for(var c=r.length-1;c>=0;){if(r[c]===t)return n[c]===e;c-=1}switch(s){case"Map":return t.size===e.size&&P(t.entries(),e.entries(),r.concat([t]),n.concat([e]));case"Set":return t.size===e.size&&P(t.values(),e.values(),r.concat([t]),n.concat([e]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var o=O(t);if(o.length!==O(e).length)return!1;var i=r.concat([t]),l=n.concat([e]);for(c=o.length-1;c>=0;){var f=o[c];if(!A(f,e)||!R(e[f],t[f],i,l))return!1;c-=1}return!0}var q=l(function(t,e){return R(t,e,[],[])});var T=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=k,t.prototype["@@transducer/result"]=v,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},t}(),L=l(g(["fantasy-land/map","map"],function(t){return function(e){return new T(t,e)}},function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return p(e.length,function(){return t.call(this,e.apply(this,arguments))});case"[object Object]":return function(t,e,r){for(var n=0,a=r.length;n<a;)e=t(e,r[n]),n+=1;return e}(function(r,n){return r[n]=t(e[n]),r},{},O(e));default:return function(t,e){for(var r=0,n=e.length,a=Array(n);r<n;)a[r]=t(e[r]),r+=1;return a}(t,e)}})),U=Number.isInteger||function(t){return(t|0)===t};function M(t,e){return e[t<0?e.length+t:t]}function V(t,e){if(null!=e)return U(t)?M(t,e):e[t]}var W=l(V),D=i(function(t){return function(){return t}}),F=i(function(t){return p(t.length,t)});var B=i(function(t){return null==t}),Q=h(function t(e,r,n){if(0===e.length)return r;var a=e[0];if(e.length>1){var u=V(a,n);(B(u)||"object"!=typeof u)&&(u=U(e[1])?[]:{}),r=t(Array.prototype.slice.call(e,1),r,u)}return function(t,e,r){if(U(t)&&y(r)){var n=t<0?r.length+t:t,a=[].concat(r);return a[n]=e,a}var u={};for(var s in r)u[s]=r[s];return u[t]=e,u}(a,r,n)}),_=Q,G=h(function(t,e,r){var n=Array.prototype.slice.call(r,0);return n.splice(t,e),n}),H=function(){function t(t,e){this.xf=e,this.f=t,this.idx=-1,this.found=!1}return t.prototype["@@transducer/init"]=k,t.prototype["@@transducer/result"]=function(t){return this.found||(t=this.xf["@@transducer/step"](t,-1)),this.xf["@@transducer/result"](t)},t.prototype["@@transducer/step"]=function(t,e){var r;return this.idx+=1,this.f(e)&&(this.found=!0,t=(r=this.xf["@@transducer/step"](t,this.idx))&&r["@@transducer/reduced"]?r:{"@@transducer/value":r,"@@transducer/reduced":!0}),t},t}();function J(t){return function(e){return new H(t,e)}}var K=l(g([],J,function(t,e){for(var r=0,n=e.length;r<n;){if(t(e[r]))return r;r+=1}return-1})),X=l(function(t,e){return function(r){return function(n){return L(function(t){return e(t,n)},r(t(n)))}}});function Y(t,e){for(var r=e,n=0;n<t.length;n+=1){if(null==r)return;var a=t[n];r=U(a)?M(a,r):r[a]}return r}var Z=i(function(t){return X(function(e){return Y(t,e)},_(t))}),$=function(t){return{value:t,map:function(e){return $(e(t))}}},tt=h(function(t,e,r){return t(function(t){return $(e(t))})(r).value}),et=tt,rt=l(Y),nt=h(function(t,e,r){return q(t,W(e,r))}),at=h(function(t,e,r){return et(t,D(e),r)}),ut=at;const st=t.createContext({}),ct=(({get:e,set:n})=>c=>{const[o,i]=t.useReducer((({set:t,get:e})=>(r={},n)=>{if(n.type===s){let a;if("function"==typeof n.data){const t=e(n.cachePath,r);a=n.data(t)}else a=n.data;return t(n.cachePath,a,r)}return{...r}})({set:n,get:e}),{}),l=t.useCallback(t=>e=>{i({type:s,cachePath:t,data:e})},[i]),f=t.useCallback(t=>e(t,o),[o,e]);return r.default.createElement(u.Provider,a({value:{get:f,set:l}},c))})({get:rt,set:(t,e,r)=>ut(Z(t),e,r)});function ot(){return t.useContext(st).sdk}const it=F((t,e,r)=>{const n=K(nt(t,e),r);return-1===n?r:G(n,1,r)}),lt=["apiTokens","status"],ft=["apiTokens","data"],dt={AuthenticationError:"AuthenticationError",NotInitialized:"NotInitialized",NotAuthenticated:"NotAuthenticated",Verifying:"Verifying",Authenticated:"Authenticated",VerifySignIn:"VerifySignIn"},pt=["auth","status"],ht=()=>{const e=ot(),r=e.workspaceId,a=t.useMemo(()=>["workspace",r],[r]),{data:u={status:n.NotInitialized,data:{}},set:s}=c(a),o=t.useCallback(()=>{s({status:n.Loading,data:{}}),e.workspaces.byId(r).then(t=>s({data:t,status:n.Success})).catch(()=>s({status:n.Error,data:{}}))},[e,r]),i=t.useCallback(t=>e.workspaces.createApiToken(r,t).then(({id:e,token:r})=>(s({status:workspaces.status,data:{...u,apiTokens:[...u.apiTokens,{id:e,description:t}]}}),r)),[e]),l=t.useCallback(t=>e.workspaces.inviteUser(r,t),[e]);return t.useEffect(()=>{r&&u.status===n.NotInitialized&&o()},[r,u]),{status:u.status,workspace:u.data,loadWorkspace:o,createApiToken:i,inviteUser:l}},yt=["workspaces"],gt=F((t,e,r)=>L(r=>r[t]===e[t]?e:r,r)),kt=e=>{const r=ot(),a=r.workspaceId,u=t.useMemo(()=>["resources",a,"status",e],[a,e]),s=t.useMemo(()=>["resources",a,"data"],[a]),{data:o,set:i}=c(u,n.NotInitialized),{data:l,set:f}=c(s,[]),d=t.useMemo(()=>l.filter(t=>t.location===e),[l,e]),p=t.useCallback(t=>{const e=l.find(e=>e.id===t);return e?Promise.resolve(e):r.resources.byId(t).then(t=>(f((e=[])=>gt("id",t,e)),t))},[r,l,f]),h=t.useCallback(()=>{i(n.Loading),r.resources.byLocation(e).then(t=>{i(n.Success),f((e=[])=>{const r=t.map(t=>t.id),n=e.filter(t=>!r.includes(t.id));return[...t,...n]})}).catch(()=>{i(n.Error)})},[r,e,i,f]),y=t.useCallback(t=>r.resources.create({type:t.type,location:t.location,name:t.name,content:t.content}).then(t=>(f((e=[])=>[...e,t]),t)),[r,f]),g=t.useCallback((t,e)=>r.resources.upload({location:t,file:e}).then(t=>(f((e=[])=>[...e,t]),t)),[r,f]),k=t.useCallback(({location:t,name:e})=>r.resources.createDirectory({location:t,name:e}).then(t=>(f((e=[])=>[...e,t]),t)),[r,f]),v=t.useCallback(t=>r.resources.remove(t).then(()=>f((e=[])=>it("id",t,e))),[r,f]),b=t.useCallback((t,e)=>r.resources.updateContent(t,e).then(t=>(f((e=[])=>gt("id",t,e)),t)),[r,a,f]),m=t.useCallback((t,e)=>r.resources.move(t,e).then(t=>(f((e=[])=>gt("id",t,e)),t)),[r,a,f]),A=t.useCallback((t,e)=>r.resources.rename(t,e).then(t=>(f((e=[])=>gt("id",t,e)),t)),[r,a,f]);return t.useEffect(()=>{a&&e&&o===n.NotInitialized&&h()},[a,e,o]),{status:o,resources:d,removeResource:v,createDocument:y,createDirectory:k,loadResource:p,updateResourceContent:b,moveResource:m,renameResource:A,uploadFile:g}},vt=["user","status"],bt=["user","data"];exports.AsyncStatus=n,exports.AuthenticationStatus=dt,exports.Context=st,exports.WorkspaceProvider=({sdk:t,children:e})=>r.default.createElement(ct,null,r.default.createElement(st.Provider,{value:{sdk:t}},e)),exports.useApiTokens=()=>{const e=ot(),{data:r=n.NotInitialized,set:a}=c(lt),{data:u=[],set:s}=c(ft),o=t.useCallback(t=>e.apiTokens.create(t).then(t=>(s(e=>[...e,t]),t)),[e]),i=t.useCallback(t=>e.apiTokens.invalidate(t).then(()=>s(e=>it("id",t,e))),[e]),l=t.useCallback(()=>{a(n.Loading),e.apiTokens.getAll().then(t=>{s(t),a(n.Success)}).catch(()=>{a(n.Error)})},[e]);return t.useEffect(()=>{r===n.NotInitialized&&l()},[r]),{status:r,tokens:u,createApiToken:o,invalidateApiToken:i}},exports.useAuthentication=()=>{const e=ot(),{data:r=dt.NotInitialized,set:n}=c(pt),a=t.useCallback(t=>(n(()=>dt.Verifying),e.auth.signUp(t).then(()=>n(dt.VerifySignIn)).catch(t=>(n(dt.AuthenticationError),Promise.reject(t)))),[e]),u=t.useCallback(t=>(n(()=>dt.Verifying),e.auth.signIn(t).then(()=>n(dt.VerifySignIn)).catch(t=>(n(dt.AuthenticationError),Promise.reject(t)))),[e]),s=t.useCallback(t=>(n(()=>dt.Verifying),e.auth.verifySignIn(t).then(()=>n(dt.Authenticated)).catch(t=>(n(dt.AuthenticationError),Promise.reject(t)))),[e]),o=t.useCallback((t,r)=>(n(()=>dt.Verifying),e.auth.verifyInvitation(t,r).then(()=>n(dt.Authenticated)).catch(t=>(n(dt.AuthenticationError),Promise.reject(t)))),[e]),i=t.useCallback(()=>e.auth.signOff().then(()=>n(dt.NotAuthenticated)),[e]);return t.useEffect(()=>{r===dt.NotInitialized&&(n(()=>dt.Verifying),e.auth.getAuthenticatedUser().then(t=>{if(!t)return Promise.reject();n(()=>dt.Authenticated)}).catch(()=>{n(()=>dt.NotAuthenticated)}))},[r]),{status:r,signUp:a,signIn:u,signOff:i,verifySignIn:s,verifyInvitation:o}},exports.useQuery=e=>{const r=ot(),a=r.workspaceId,u=new URLSearchParams(e).toString();console.log("useQuery",e,u);const s=t.useMemo(()=>[a,"queries",u,"status"],[a,u]),o=t.useMemo(()=>[a,"queries",u,"data"],[a,u]),{data:i,set:l}=c(s,n.NotInitialized),{data:f,set:d}=c(o,[]),p=t.useCallback(t=>{l(n.Loading),r.resources.get(t).then(t=>{l(n.Success),d(t)}).catch(()=>{l(n.Error)})},[r]);return t.useEffect(()=>{console.log("useQuery effect",a,e,i),a&&e&&i===n.NotInitialized&&p(e)},[a,e,i]),{status:i,resources:f}},exports.useResource=e=>{const r=ot().workspaceId,a=t.useMemo(()=>["resource",r,e,"status"],[e,r]),u=t.useMemo(()=>["resource",r,e,"data"],[e,r]),{data:s=n.NotInitialized,set:o}=c(a),{data:i={},set:l}=c(u),{loadResource:f,removeResource:d,updateResourceContent:p,renameResource:h}=kt(),y=t.useCallback(()=>{o(n.Loading),l({}),f(e).then(t=>{o(n.Success),l(t)}).catch(()=>{o(n.Error),l({})})},[e,f]),g=t.useCallback(()=>d(e).then(()=>{o(n.NotInitialized),l({})}),[e,d]),k=t.useCallback(t=>p(e,t).then(t=>l(t)),[e,p]),v=t.useCallback(t=>h(e,t).then(t=>l(t)),[e,h]);return t.useEffect(()=>{r&&e&&s===n.NotInitialized&&y()},[r,e,y]),{status:s,resource:i,loadResource:y,removeResource:g,updateResourceContent:k,renameResource:v}},exports.useResourceTemplate=t=>{const{workspace:e}=ht();return e.resourceTemplates.find(e=>e.id===t)},exports.useResources=kt,exports.useSdk=ot,exports.useUser=()=>{const e=ot(),{data:r=n.NotInitialized,set:a}=c(vt),{data:u={},set:s}=c(bt),o=t.useCallback(t=>e.user.update(t).then(t=>(s(t),t)),[e]);return t.useEffect(()=>{r===n.NotInitialized&&(a(()=>n.Loading),e.user.details().then(t=>{if(!t)return Promise.reject();s(t),a(()=>n.Success)}).catch(()=>{s({}),a(()=>n.Error)}))},[r]),{status:r,user:u,update:o}},exports.useUsers=()=>{const e=ot(),r=e.workspaceId,a=t.useMemo(()=>["workspace",r,"users"],[r]),{data:u={status:n.NotInitialized,data:[]},set:s}=c(a),o=t.useCallback(()=>{s({status:n.Loading,data:[]}),e.workspaces.users().then(t=>s({data:t,status:n.Success})).catch(()=>s({status:n.Error,data:[]}))},[e]);return t.useEffect(()=>{r&&u.status===n.NotInitialized&&o()},[r,u]),{status:u.status,users:u.data,load:o}},exports.useWorkspace=ht,exports.useWorkspaces=()=>{const e=ot(),{set:r,data:a={status:n.NotInitialized,data:[]}}=c(yt),u=t.useCallback(()=>{r({status:n.Loading,data:[]}),e.workspaces.getAll().then(t=>r({status:n.Success,data:t})).catch(()=>r({status:n.Error,data:[]}))},[e]),s=t.useCallback(t=>e.workspaces.create(t).then(t=>(r({status:a.status,data:[...a.data,t]}),t)),[e]);return t.useEffect(()=>{a.status===n.NotInitialized&&u()},[a,u]),{status:a.status,workspaces:a.data,loadWorkspaces:u,createWorkspace:s}};
|
package/build/index.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t,{useContext as e,createContext as r,useReducer as n,useCallback as a,useEffect as u,useMemo as o}from"react";const i={NotInitialized:"NotInitialized",Loading:"Loading",Success:"Success",Error:"Error"};function c(){return c=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},c.apply(null,arguments)}const s=r(),f="SET",l=(t,r)=>{const{get:n,set:a}=e(s);return{data:(()=>{const e=n(t);return null==e?r:e})(),set:a(t)}};function d(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function p(t){return function e(r){return 0===arguments.length||d(r)?e:t.apply(this,arguments)}}function h(t){return function e(r,n){switch(arguments.length){case 0:return e;case 1:return d(r)?e:p((function(e){return t(r,e)}));default:return d(r)&&d(n)?e:d(r)?p((function(e){return t(e,n)})):d(n)?p((function(e){return t(r,e)})):t(r,n)}}}function y(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,r){return e.apply(this,arguments)};case 3:return function(t,r,n){return e.apply(this,arguments)};case 4:return function(t,r,n,a){return e.apply(this,arguments)};case 5:return function(t,r,n,a,u){return e.apply(this,arguments)};case 6:return function(t,r,n,a,u,o){return e.apply(this,arguments)};case 7:return function(t,r,n,a,u,o,i){return e.apply(this,arguments)};case 8:return function(t,r,n,a,u,o,i,c){return e.apply(this,arguments)};case 9:return function(t,r,n,a,u,o,i,c,s){return e.apply(this,arguments)};case 10:return function(t,r,n,a,u,o,i,c,s,f){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function g(t,e,r){return function(){for(var n=[],a=0,u=t,o=0;o<e.length||a<arguments.length;){var i;o<e.length&&(!d(e[o])||a>=arguments.length)?i=e[o]:(i=arguments[a],a+=1),n[o]=i,d(i)||(u-=1),o+=1}return u<=0?r.apply(this,n):y(u,g(t,n,r))}}var v=h((function(t,e){return 1===t?p(e):y(t,g(t,[],e))}));function m(t){return function e(r,n,a){switch(arguments.length){case 0:return e;case 1:return d(r)?e:h((function(e,n){return t(r,e,n)}));case 2:return d(r)&&d(n)?e:d(r)?h((function(e,r){return t(e,n,r)})):d(n)?h((function(e,n){return t(r,e,n)})):p((function(e){return t(r,n,e)}));default:return d(r)&&d(n)&&d(a)?e:d(r)&&d(n)?h((function(e,r){return t(e,r,a)})):d(r)&&d(a)?h((function(e,r){return t(e,n,r)})):d(n)&&d(a)?h((function(e,n){return t(r,e,n)})):d(r)?p((function(e){return t(e,n,a)})):d(n)?p((function(e){return t(r,e,a)})):d(a)?p((function(e){return t(r,n,e)})):t(r,n,a)}}}var b=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)};function k(t,e,r){return function(){if(0===arguments.length)return r();var n=Array.prototype.slice.call(arguments,0),a=n.pop();if(!b(a)){for(var u=0;u<t.length;){if("function"==typeof a[t[u]])return a[t[u]].apply(a,n);u+=1}if(function(t){return null!=t&&"function"==typeof t["@@transducer/step"]}(a))return e.apply(null,n)(a)}return r.apply(this,arguments)}}var I=function(){return this.xf["@@transducer/init"]()},A=function(t){return this.xf["@@transducer/result"](t)};function w(t){return"[object String]"===Object.prototype.toString.call(t)}var S=p((function(t){return!!b(t)||!!t&&("object"==typeof t&&(!w(t)&&(1===t.nodeType?!!t.length:0===t.length||t.length>0&&(t.hasOwnProperty(0)&&t.hasOwnProperty(t.length-1)))))})),j=function(){function t(t){this.f=t}return t.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},t.prototype["@@transducer/result"]=function(t){return t},t.prototype["@@transducer/step"]=function(t,e){return this.f(t,e)},t}();var N=h((function(t,e){return y(t.length,(function(){return t.apply(e,arguments)}))}));function E(t,e,r){for(var n=r.next();!n.done;){if((e=t["@@transducer/step"](e,n.value))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}n=r.next()}return t["@@transducer/result"](e)}function O(t,e,r,n){return t["@@transducer/result"](r[n](N(t["@@transducer/step"],t),e))}var z="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";function P(t,e,r){if("function"==typeof t&&(t=function(t){return new j(t)}(t)),S(r))return function(t,e,r){for(var n=0,a=r.length;n<a;){if((e=t["@@transducer/step"](e,r[n]))&&e["@@transducer/reduced"]){e=e["@@transducer/value"];break}n+=1}return t["@@transducer/result"](e)}(t,e,r);if("function"==typeof r["fantasy-land/reduce"])return O(t,e,r,"fantasy-land/reduce");if(null!=r[z])return E(t,e,r[z]());if("function"==typeof r.next)return E(t,e,r);if("function"==typeof r.reduce)return O(t,e,r,"reduce");throw new TypeError("reduce: list must be array or iterable")}var x=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=I,t.prototype["@@transducer/result"]=A,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},t}(),R=h((function(t,e){return new x(t,e)}));function T(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var q=Object.prototype.toString,L=function(){return"[object Arguments]"===q.call(arguments)?function(t){return"[object Arguments]"===q.call(t)}:function(t){return T("callee",t)}}(),U=!{toString:null}.propertyIsEnumerable("toString"),V=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],C=function(){return arguments.propertyIsEnumerable("length")}(),D=function(t,e){for(var r=0;r<t.length;){if(t[r]===e)return!0;r+=1}return!1},F="function"!=typeof Object.keys||C?p((function(t){if(Object(t)!==t)return[];var e,r,n=[],a=C&&L(t);for(e in t)!T(e,t)||a&&"length"===e||(n[n.length]=e);if(U)for(r=V.length-1;r>=0;)T(e=V[r],t)&&!D(n,e)&&(n[n.length]=e),r-=1;return n})):p((function(t){return Object(t)!==t?[]:Object.keys(t)})),W=h(k(["fantasy-land/map","map"],R,(function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return v(e.length,(function(){return t.call(this,e.apply(this,arguments))}));case"[object Object]":return P((function(r,n){return r[n]=t(e[n]),r}),{},F(e));default:return function(t,e){for(var r=0,n=e.length,a=Array(n);r<n;)a[r]=t(e[r]),r+=1;return a}(t,e)}}))),B=Number.isInteger||function(t){return(t|0)===t},Q=h((function(t,e){var r=t<0?e.length+t:t;return w(e)?e.charAt(r):e[r]})),M=h((function(t,e){return t.map((function(t){for(var r,n=e,a=0;a<t.length;){if(null==n)return;r=t[a],n=B(r)?Q(r,n):n[r],a+=1}return n}))})),X=h((function(t,e){return M([t],e)[0]})),_=p((function(t){return function(){return t}})),G=m((function(t,e,r){var n={};for(var a in r)n[a]=r[a];return n[t]=e,n})),H=p((function(t){return null==t})),J=m((function t(e,r,n){if(0===e.length)return r;var a=e[0];if(e.length>1){var u=!H(n)&&T(a,n)?n[a]:B(e[1])?[]:{};r=t(Array.prototype.slice.call(e,1),r,u)}if(B(a)&&b(n)){var o=[].concat(n);return o[a]=r,o}return G(a,r,n)})),K=J,Y=p((function(t){return v(t.length,t)})),Z=p((function(t){return null===t?"Null":void 0===t?"Undefined":Object.prototype.toString.call(t).slice(8,-1)}));function $(t){for(var e,r=[];!(e=t.next()).done;)r.push(e.value);return r}function tt(t,e,r){for(var n=0,a=r.length;n<a;){if(t(e,r[n]))return!0;n+=1}return!1}var et="function"==typeof Object.is?Object.is:function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e};function rt(t,e,r,n){var a=$(t);function u(t,e){return nt(t,e,r.slice(),n.slice())}return!tt((function(t,e){return!tt(u,e,t)}),$(e),a)}function nt(t,e,r,n){if(et(t,e))return!0;var a,u,o=Z(t);if(o!==Z(e))return!1;if(null==t||null==e)return!1;if("function"==typeof t["fantasy-land/equals"]||"function"==typeof e["fantasy-land/equals"])return"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e)&&"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t);if("function"==typeof t.equals||"function"==typeof e.equals)return"function"==typeof t.equals&&t.equals(e)&&"function"==typeof e.equals&&e.equals(t);switch(o){case"Arguments":case"Array":case"Object":if("function"==typeof t.constructor&&"Promise"===(a=t.constructor,null==(u=String(a).match(/^function (\w*)/))?"":u[1]))return t===e;break;case"Boolean":case"Number":case"String":if(typeof t!=typeof e||!et(t.valueOf(),e.valueOf()))return!1;break;case"Date":if(!et(t.valueOf(),e.valueOf()))return!1;break;case"Error":return t.name===e.name&&t.message===e.message;case"RegExp":if(t.source!==e.source||t.global!==e.global||t.ignoreCase!==e.ignoreCase||t.multiline!==e.multiline||t.sticky!==e.sticky||t.unicode!==e.unicode)return!1}for(var i=r.length-1;i>=0;){if(r[i]===t)return n[i]===e;i-=1}switch(o){case"Map":return t.size===e.size&&rt(t.entries(),e.entries(),r.concat([t]),n.concat([e]));case"Set":return t.size===e.size&&rt(t.values(),e.values(),r.concat([t]),n.concat([e]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var c=F(t);if(c.length!==F(e).length)return!1;var s=r.concat([t]),f=n.concat([e]);for(i=c.length-1;i>=0;){var l=c[i];if(!T(l,e)||!nt(e[l],t[l],s,f))return!1;i-=1}return!0}var at=h((function(t,e){return nt(t,e,[],[])})),ut=m((function(t,e,r){var n=Array.prototype.slice.call(r,0);return n.splice(t,e),n})),ot=function(){function t(t,e){this.xf=e,this.f=t,this.idx=-1,this.found=!1}return t.prototype["@@transducer/init"]=I,t.prototype["@@transducer/result"]=function(t){return this.found||(t=this.xf["@@transducer/step"](t,-1)),this.xf["@@transducer/result"](t)},t.prototype["@@transducer/step"]=function(t,e){var r;return this.idx+=1,this.f(e)&&(this.found=!0,t=(r=this.xf["@@transducer/step"](t,this.idx))&&r["@@transducer/reduced"]?r:{"@@transducer/value":r,"@@transducer/reduced":!0}),t},t}(),it=h(k([],h((function(t,e){return new ot(t,e)})),(function(t,e){for(var r=0,n=e.length;r<n;){if(t(e[r]))return r;r+=1}return-1}))),ct=h((function(t,e){return function(r){return function(n){return W((function(t){return e(t,n)}),r(t(n)))}}})),st=p((function(t){return ct(X(t),K(t))})),ft=function(t){return{value:t,map:function(e){return ft(e(t))}}},lt=m((function(t,e,r){return t((function(t){return ft(e(t))}))(r).value})),dt=lt,pt=m((function(t,e,r){return at(e,r[t])})),ht=m((function(t,e,r){return dt(t,_(e),r)})),yt=ht;const gt=r({}),vt=(({get:e,set:r})=>u=>{const[o,i]=n((({set:t,get:e})=>(r={},n)=>{if(n.type===f){let a;if("function"==typeof n.data){const t=e(n.cachePath,r);a=n.data(t)}else a=n.data;return t(n.cachePath,a,r)}return{...r}})({set:r,get:e}),{}),l=a((t=>e=>{i({type:f,cachePath:t,data:e})}),[i]),d=a((t=>e(t,o)),[o,e]);return t.createElement(s.Provider,c({value:{get:d,set:l}},u))})({get:X,set:(t,e,r)=>yt(st(t),e,r)}),mt=({sdk:e,children:r})=>t.createElement(vt,null,t.createElement(gt.Provider,{value:{sdk:e}},r));function bt(){return e(gt).sdk}const kt=Y(((t,e,r)=>{const n=it(pt(t,e),r);return-1===n?r:ut(n,1,r)})),It=["apiTokens","status"],At=["apiTokens","data"],wt=()=>{const t=bt(),{data:e=i.NotInitialized,set:r}=l(It),{data:n=[],set:o}=l(At),c=a((e=>t.apiTokens.create(e).then((t=>(o((e=>[...e,t])),t)))),[t]),s=a((e=>t.apiTokens.invalidate(e).then((()=>o((t=>kt("id",e,t)))))),[t]),f=a((()=>{r(i.Loading),t.apiTokens.getAll().then((t=>{o(t),r(i.Success)})).catch((()=>{r(i.Error)}))}),[t]);return u((()=>{e===i.NotInitialized&&f()}),[e]),{status:e,tokens:n,createApiToken:c,invalidateApiToken:s}},St={AuthenticationError:"AuthenticationError",NotInitialized:"NotInitialized",NotAuthenticated:"NotAuthenticated",Verifying:"Verifying",Authenticated:"Authenticated",VerifySignIn:"VerifySignIn"},jt=["auth","status"],Nt=()=>{const t=bt(),{data:e=St.NotInitialized,set:r}=l(jt),n=a((e=>(r((()=>St.Verifying)),t.auth.signUp(e).then((()=>r(St.VerifySignIn))).catch((t=>(r(St.AuthenticationError),Promise.reject(t)))))),[t]),o=a((e=>(r((()=>St.Verifying)),t.auth.signIn(e).then((()=>r(St.VerifySignIn))).catch((t=>(r(St.AuthenticationError),Promise.reject(t)))))),[t]),i=a((e=>(r((()=>St.Verifying)),t.auth.verifySignIn(e).then((()=>r(St.Authenticated))).catch((t=>(r(St.AuthenticationError),Promise.reject(t)))))),[t]),c=a(((e,n)=>(r((()=>St.Verifying)),t.auth.verifyInvitation(e,n).then((()=>r(St.Authenticated))).catch((t=>(r(St.AuthenticationError),Promise.reject(t)))))),[t]),s=a((()=>t.auth.signOff().then((()=>r(St.NotAuthenticated)))),[t]);return u((()=>{e===St.NotInitialized&&(r((()=>St.Verifying)),t.auth.getAuthenticatedUser().then((t=>{if(!t)return Promise.reject();r((()=>St.Authenticated))})).catch((()=>{r((()=>St.NotAuthenticated))})))}),[e]),{status:e,signUp:n,signIn:o,signOff:s,verifySignIn:i,verifyInvitation:c}},Et=()=>{const t=bt(),e=t.workspaceId,r=o((()=>["workspace",e]),[e]),{data:n={status:i.NotInitialized,data:{}},set:c}=l(r),s=a((()=>{c({status:i.Loading,data:{}}),t.workspaces.byId(e).then((t=>c({data:t,status:i.Success}))).catch((()=>c({status:i.Error,data:{}})))}),[t,e]),f=a((r=>t.workspaces.createApiToken(e,r).then((({id:t,token:e})=>(c({status:workspaces.status,data:{...n,apiTokens:[...n.apiTokens,{id:t,description:r}]}}),e)))),[t]),d=a((r=>t.workspaces.inviteUser(e,r)),[t]);return u((()=>{e&&n.status===i.NotInitialized&&s()}),[e,n]),{status:n.status,workspace:n.data,loadWorkspace:s,createApiToken:f,inviteUser:d}},Ot=["workspaces"],zt=()=>{const t=bt(),{set:e,data:r={status:i.NotInitialized,data:[]}}=l(Ot),n=a((()=>{e({status:i.Loading,data:[]}),t.workspaces.getAll().then((t=>e({status:i.Success,data:t}))).catch((()=>e({status:i.Error,data:[]})))}),[t]),o=a((n=>t.workspaces.create(n).then((t=>(e({status:r.status,data:[...r.data,t]}),t)))),[t]);return u((()=>{r.status===i.NotInitialized&&n()}),[r,n]),{status:r.status,workspaces:r.data,loadWorkspaces:n,createWorkspace:o}},Pt=t=>{const e=bt(),r=e.workspaceId,n=new URLSearchParams(t).toString();console.log("useQuery",t,n);const c=o((()=>[r,"queries",n,"status"]),[r,n]),s=o((()=>[r,"queries",n,"data"]),[r,n]),{data:f,set:d}=l(c,i.NotInitialized),{data:p,set:h}=l(s,[]),y=a((t=>{d(i.Loading),e.resources.get(t).then((t=>{d(i.Success),h(t)})).catch((()=>{d(i.Error)}))}),[e]);return u((()=>{console.log("useQuery effect",r,t,f),r&&t&&f===i.NotInitialized&&y(t)}),[r,t,f]),{status:f,resources:p}},xt=Y(((t,e,r)=>W((r=>r[t]===e[t]?e:r),r))),Rt=t=>{const e=bt(),r=e.workspaceId,n=o((()=>["resources",r,"status",t]),[r,t]),c=o((()=>["resources",r,"data"]),[r]),{data:s,set:f}=l(n,i.NotInitialized),{data:d,set:p}=l(c,[]),h=o((()=>d.filter((e=>e.location===t))),[d,t]),y=a((t=>{const r=d.find((e=>e.id===t));return r?Promise.resolve(r):e.resources.byId(t).then((t=>(p(((e=[])=>xt("id",t,e))),t)))}),[e,d,p]),g=a((()=>{f(i.Loading),e.resources.byLocation(t).then((t=>{f(i.Success),p(((e=[])=>{const r=t.map((t=>t.id)),n=e.filter((t=>!r.includes(t.id)));return[...t,...n]}))})).catch((()=>{f(i.Error)}))}),[e,t,f,p]),v=a((t=>e.resources.create({type:t.type,location:t.location,name:t.name,content:t.content}).then((t=>(p(((e=[])=>[...e,t])),t)))),[e,p]),m=a(((t,r)=>e.resources.upload({location:t,file:r}).then((t=>(p(((e=[])=>[...e,t])),t)))),[e,p]),b=a((({location:t,name:r})=>e.resources.createDirectory({location:t,name:r}).then((t=>(p(((e=[])=>[...e,t])),t)))),[e,p]),k=a((t=>e.resources.remove(t).then((()=>p(((e=[])=>kt("id",t,e)))))),[e,p]),I=a(((t,r)=>e.resources.updateContent(t,r).then((t=>(p(((e=[])=>xt("id",t,e))),t)))),[e,r,p]),A=a(((t,r)=>e.resources.move(t,r).then((t=>(p(((e=[])=>xt("id",t,e))),t)))),[e,r,p]),w=a(((t,r)=>e.resources.rename(t,r).then((t=>(p(((e=[])=>xt("id",t,e))),t)))),[e,r,p]);return u((()=>{r&&t&&s===i.NotInitialized&&g()}),[r,t,s]),{status:s,resources:h,removeResource:k,createDocument:v,createDirectory:b,loadResource:y,updateResourceContent:I,moveResource:A,renameResource:w,uploadFile:m}},Tt=t=>{const e=bt().workspaceId,r=o((()=>["resource",e,t,"status"]),[t,e]),n=o((()=>["resource",e,t,"data"]),[t,e]),{data:c=i.NotInitialized,set:s}=l(r),{data:f={},set:d}=l(n),{loadResource:p,removeResource:h,updateResourceContent:y,renameResource:g}=Rt(),v=a((()=>{s(i.Loading),d({}),p(t).then((t=>{s(i.Success),d(t)})).catch((()=>{s(i.Error),d({})}))}),[t,p]),m=a((()=>h(t).then((()=>{s(i.NotInitialized),d({})}))),[t,h]),b=a((e=>y(t,e).then((t=>d(t)))),[t,y]),k=a((e=>g(t,e).then((t=>d(t)))),[t,g]);return u((()=>{e&&t&&c===i.NotInitialized&&v()}),[e,t,v]),{status:c,resource:f,loadResource:v,removeResource:m,updateResourceContent:b,renameResource:k}},qt=t=>{const{workspace:e}=Et();return e.resourceTemplates.find((e=>e.id===t))},Lt=["user","status"],Ut=["user","data"],Vt=()=>{const t=bt(),{data:e=i.NotInitialized,set:r}=l(Lt),{data:n={},set:o}=l(Ut),c=a((e=>t.user.update(e).then((t=>(o(t),t)))),[t]);return u((()=>{e===i.NotInitialized&&(r((()=>i.Loading)),t.user.details().then((t=>{if(!t)return Promise.reject();o(t),r((()=>i.Success))})).catch((()=>{o({}),r((()=>i.Error))})))}),[e]),{status:e,user:n,update:c}},Ct=()=>{const t=bt(),e=t.workspaceId,r=o((()=>["workspace",e,"users"]),[e]),{data:n={status:i.NotInitialized,data:[]},set:c}=l(r),s=a((()=>{c({status:i.Loading,data:[]}),t.workspaces.users().then((t=>c({data:t,status:i.Success}))).catch((()=>c({status:i.Error,data:[]})))}),[t]);return u((()=>{e&&n.status===i.NotInitialized&&s()}),[e,n]),{status:n.status,users:n.data,load:s}};export{i as AsyncStatus,St as AuthenticationStatus,gt as Context,mt as WorkspaceProvider,wt as useApiTokens,Nt as useAuthentication,Pt as useQuery,Tt as useResource,qt as useResourceTemplate,Rt as useResources,bt as useSdk,Vt as useUser,Ct as useUsers,Et as useWorkspace,zt as useWorkspaces};
|
|
1
|
+
import t,{useContext as e,createContext as n,useReducer as r,useCallback as a,useEffect as u,useMemo as i}from"react";const o={NotInitialized:"NotInitialized",Loading:"Loading",Success:"Success",Error:"Error"};function s(){return s=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},s.apply(null,arguments)}const c=n(),f="SET",l=(t,n)=>{const{get:r,set:a}=e(c);return{data:(()=>{const e=r(t);return null==e?n:e})(),set:a(t)}};function d(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function p(t){return function e(n){return 0===arguments.length||d(n)?e:t.apply(this,arguments)}}function h(t){return function e(n,r){switch(arguments.length){case 0:return e;case 1:return d(n)?e:p(function(e){return t(n,e)});default:return d(n)&&d(r)?e:d(n)?p(function(e){return t(e,r)}):d(r)?p(function(e){return t(n,e)}):t(n,r)}}}function y(t,e){switch(t){case 0:return function(){return e.apply(this,arguments)};case 1:return function(t){return e.apply(this,arguments)};case 2:return function(t,n){return e.apply(this,arguments)};case 3:return function(t,n,r){return e.apply(this,arguments)};case 4:return function(t,n,r,a){return e.apply(this,arguments)};case 5:return function(t,n,r,a,u){return e.apply(this,arguments)};case 6:return function(t,n,r,a,u,i){return e.apply(this,arguments)};case 7:return function(t,n,r,a,u,i,o){return e.apply(this,arguments)};case 8:return function(t,n,r,a,u,i,o,s){return e.apply(this,arguments)};case 9:return function(t,n,r,a,u,i,o,s,c){return e.apply(this,arguments)};case 10:return function(t,n,r,a,u,i,o,s,c,f){return e.apply(this,arguments)};default:throw new Error("First argument to _arity must be a non-negative integer no greater than ten")}}function g(t,e,n){return function(){for(var r=[],a=0,u=t,i=0,o=!1;i<e.length||a<arguments.length;){var s;i<e.length&&(!d(e[i])||a>=arguments.length)?s=e[i]:(s=arguments[a],a+=1),r[i]=s,d(s)?o=!0:u-=1,i+=1}return!o&&u<=0?n.apply(this,r):y(Math.max(0,u),g(t,r,n))}}var v=h(function(t,e){return 1===t?p(e):y(t,g(t,[],e))});function m(t){return function e(n,r,a){switch(arguments.length){case 0:return e;case 1:return d(n)?e:h(function(e,r){return t(n,e,r)});case 2:return d(n)&&d(r)?e:d(n)?h(function(e,n){return t(e,r,n)}):d(r)?h(function(e,r){return t(n,e,r)}):p(function(e){return t(n,r,e)});default:return d(n)&&d(r)&&d(a)?e:d(n)&&d(r)?h(function(e,n){return t(e,n,a)}):d(n)&&d(a)?h(function(e,n){return t(e,r,n)}):d(r)&&d(a)?h(function(e,r){return t(n,e,r)}):d(n)?p(function(e){return t(e,r,a)}):d(r)?p(function(e){return t(n,e,a)}):d(a)?p(function(e){return t(n,r,e)}):t(n,r,a)}}}var I=Array.isArray||function(t){return null!=t&&t.length>=0&&"[object Array]"===Object.prototype.toString.call(t)};function A(t,e,n){return function(){if(0===arguments.length)return n();var r=arguments[arguments.length-1];if(!I(r)){for(var a=0;a<t.length;){if("function"==typeof r[t[a]])return r[t[a]].apply(r,Array.prototype.slice.call(arguments,0,-1));a+=1}if(function(t){return null!=t&&"function"==typeof t["@@transducer/step"]}(r))return e.apply(null,Array.prototype.slice.call(arguments,0,-1))(r)}return n.apply(this,arguments)}}var k=function(){return this.xf["@@transducer/init"]()},b=function(t){return this.xf["@@transducer/result"](t)};function w(t){for(var e,n=[];!(e=t.next()).done;)n.push(e.value);return n}function N(t,e,n){for(var r=0,a=n.length;r<a;){if(t(e,n[r]))return!0;r+=1}return!1}function S(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var j="function"==typeof Object.is?Object.is:function(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e},E=Object.prototype.toString,z=function(){return"[object Arguments]"===E.call(arguments)?function(t){return"[object Arguments]"===E.call(t)}:function(t){return S("callee",t)}}(),O=!{toString:null}.propertyIsEnumerable("toString"),P=["constructor","valueOf","isPrototypeOf","toString","propertyIsEnumerable","hasOwnProperty","toLocaleString"],x=function(){return arguments.propertyIsEnumerable("length")}(),R=function(t,e){for(var n=0;n<t.length;){if(t[n]===e)return!0;n+=1}return!1},q="function"!=typeof Object.keys||x?p(function(t){if(Object(t)!==t)return[];var e,n,r=[],a=x&&z(t);for(e in t)!S(e,t)||a&&"length"===e||(r[r.length]=e);if(O)for(n=P.length-1;n>=0;)S(e=P[n],t)&&!R(r,e)&&(r[r.length]=e),n-=1;return r}):p(function(t){return Object(t)!==t?[]:Object.keys(t)}),L=q,T=p(function(t){return null===t?"Null":void 0===t?"Undefined":Object.prototype.toString.call(t).slice(8,-1)});function U(t,e,n,r){var a=w(t);function u(t,e){return V(t,e,n.slice(),r.slice())}return!N(function(t,e){return!N(u,e,t)},w(e),a)}function V(t,e,n,r){if(j(t,e))return!0;var a,u,i=T(t);if(i!==T(e))return!1;if("function"==typeof t["fantasy-land/equals"]||"function"==typeof e["fantasy-land/equals"])return"function"==typeof t["fantasy-land/equals"]&&t["fantasy-land/equals"](e)&&"function"==typeof e["fantasy-land/equals"]&&e["fantasy-land/equals"](t);if("function"==typeof t.equals||"function"==typeof e.equals)return"function"==typeof t.equals&&t.equals(e)&&"function"==typeof e.equals&&e.equals(t);switch(i){case"Arguments":case"Array":case"Object":if("function"==typeof t.constructor&&"Promise"===(a=t.constructor,null==(u=String(a).match(/^function (\w*)/))?"":u[1]))return t===e;break;case"Boolean":case"Number":case"String":if(typeof t!=typeof e||!j(t.valueOf(),e.valueOf()))return!1;break;case"Date":if(!j(t.valueOf(),e.valueOf()))return!1;break;case"Error":return t.name===e.name&&t.message===e.message;case"RegExp":if(t.source!==e.source||t.global!==e.global||t.ignoreCase!==e.ignoreCase||t.multiline!==e.multiline||t.sticky!==e.sticky||t.unicode!==e.unicode)return!1}for(var o=n.length-1;o>=0;){if(n[o]===t)return r[o]===e;o-=1}switch(i){case"Map":return t.size===e.size&&U(t.entries(),e.entries(),n.concat([t]),r.concat([e]));case"Set":return t.size===e.size&&U(t.values(),e.values(),n.concat([t]),r.concat([e]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var s=L(t);if(s.length!==L(e).length)return!1;var c=n.concat([t]),f=r.concat([e]);for(o=s.length-1;o>=0;){var l=s[o];if(!S(l,e)||!V(e[l],t[l],c,f))return!1;o-=1}return!0}var C=h(function(t,e){return V(t,e,[],[])});var D=function(){function t(t,e){this.xf=e,this.f=t}return t.prototype["@@transducer/init"]=k,t.prototype["@@transducer/result"]=b,t.prototype["@@transducer/step"]=function(t,e){return this.xf["@@transducer/step"](t,this.f(e))},t}(),F=h(A(["fantasy-land/map","map"],function(t){return function(e){return new D(t,e)}},function(t,e){switch(Object.prototype.toString.call(e)){case"[object Function]":return v(e.length,function(){return t.call(this,e.apply(this,arguments))});case"[object Object]":return function(t,e,n){for(var r=0,a=n.length;r<a;)e=t(e,n[r]),r+=1;return e}(function(n,r){return n[r]=t(e[r]),n},{},L(e));default:return function(t,e){for(var n=0,r=e.length,a=Array(r);n<r;)a[n]=t(e[n]),n+=1;return a}(t,e)}})),B=Number.isInteger||function(t){return(t|0)===t};function W(t,e){return e[t<0?e.length+t:t]}function M(t,e){if(null!=e)return B(t)?W(t,e):e[t]}var Q=h(M),_=p(function(t){return function(){return t}}),G=p(function(t){return v(t.length,t)});var H=p(function(t){return null==t}),J=m(function t(e,n,r){if(0===e.length)return n;var a=e[0];if(e.length>1){var u=M(a,r);(H(u)||"object"!=typeof u)&&(u=B(e[1])?[]:{}),n=t(Array.prototype.slice.call(e,1),n,u)}return function(t,e,n){if(B(t)&&I(n)){var r=t<0?n.length+t:t,a=[].concat(n);return a[r]=e,a}var u={};for(var i in n)u[i]=n[i];return u[t]=e,u}(a,n,r)}),K=J,X=m(function(t,e,n){var r=Array.prototype.slice.call(n,0);return r.splice(t,e),r}),Y=function(){function t(t,e){this.xf=e,this.f=t,this.idx=-1,this.found=!1}return t.prototype["@@transducer/init"]=k,t.prototype["@@transducer/result"]=function(t){return this.found||(t=this.xf["@@transducer/step"](t,-1)),this.xf["@@transducer/result"](t)},t.prototype["@@transducer/step"]=function(t,e){var n;return this.idx+=1,this.f(e)&&(this.found=!0,t=(n=this.xf["@@transducer/step"](t,this.idx))&&n["@@transducer/reduced"]?n:{"@@transducer/value":n,"@@transducer/reduced":!0}),t},t}();function Z(t){return function(e){return new Y(t,e)}}var $=h(A([],Z,function(t,e){for(var n=0,r=e.length;n<r;){if(t(e[n]))return n;n+=1}return-1})),tt=h(function(t,e){return function(n){return function(r){return F(function(t){return e(t,r)},n(t(r)))}}});function et(t,e){for(var n=e,r=0;r<t.length;r+=1){if(null==n)return;var a=t[r];n=B(a)?W(a,n):n[a]}return n}var nt=p(function(t){return tt(function(e){return et(t,e)},K(t))}),rt=function(t){return{value:t,map:function(e){return rt(e(t))}}},at=m(function(t,e,n){return t(function(t){return rt(e(t))})(n).value}),ut=at,it=h(et),ot=m(function(t,e,n){return C(t,Q(e,n))}),st=m(function(t,e,n){return ut(t,_(e),n)}),ct=st;const ft=n({}),lt=(({get:e,set:n})=>u=>{const[i,o]=r((({set:t,get:e})=>(n={},r)=>{if(r.type===f){let a;if("function"==typeof r.data){const t=e(r.cachePath,n);a=r.data(t)}else a=r.data;return t(r.cachePath,a,n)}return{...n}})({set:n,get:e}),{}),l=a(t=>e=>{o({type:f,cachePath:t,data:e})},[o]),d=a(t=>e(t,i),[i,e]);return t.createElement(c.Provider,s({value:{get:d,set:l}},u))})({get:it,set:(t,e,n)=>ct(nt(t),e,n)}),dt=({sdk:e,children:n})=>t.createElement(lt,null,t.createElement(ft.Provider,{value:{sdk:e}},n));function pt(){return e(ft).sdk}const ht=G((t,e,n)=>{const r=$(ot(t,e),n);return-1===r?n:X(r,1,n)}),yt=["apiTokens","status"],gt=["apiTokens","data"],vt=()=>{const t=pt(),{data:e=o.NotInitialized,set:n}=l(yt),{data:r=[],set:i}=l(gt),s=a(e=>t.apiTokens.create(e).then(t=>(i(e=>[...e,t]),t)),[t]),c=a(e=>t.apiTokens.invalidate(e).then(()=>i(t=>ht("id",e,t))),[t]),f=a(()=>{n(o.Loading),t.apiTokens.getAll().then(t=>{i(t),n(o.Success)}).catch(()=>{n(o.Error)})},[t]);return u(()=>{e===o.NotInitialized&&f()},[e]),{status:e,tokens:r,createApiToken:s,invalidateApiToken:c}},mt={AuthenticationError:"AuthenticationError",NotInitialized:"NotInitialized",NotAuthenticated:"NotAuthenticated",Verifying:"Verifying",Authenticated:"Authenticated",VerifySignIn:"VerifySignIn"},It=["auth","status"],At=()=>{const t=pt(),{data:e=mt.NotInitialized,set:n}=l(It),r=a(e=>(n(()=>mt.Verifying),t.auth.signUp(e).then(()=>n(mt.VerifySignIn)).catch(t=>(n(mt.AuthenticationError),Promise.reject(t)))),[t]),i=a(e=>(n(()=>mt.Verifying),t.auth.signIn(e).then(()=>n(mt.VerifySignIn)).catch(t=>(n(mt.AuthenticationError),Promise.reject(t)))),[t]),o=a(e=>(n(()=>mt.Verifying),t.auth.verifySignIn(e).then(()=>n(mt.Authenticated)).catch(t=>(n(mt.AuthenticationError),Promise.reject(t)))),[t]),s=a((e,r)=>(n(()=>mt.Verifying),t.auth.verifyInvitation(e,r).then(()=>n(mt.Authenticated)).catch(t=>(n(mt.AuthenticationError),Promise.reject(t)))),[t]),c=a(()=>t.auth.signOff().then(()=>n(mt.NotAuthenticated)),[t]);return u(()=>{e===mt.NotInitialized&&(n(()=>mt.Verifying),t.auth.getAuthenticatedUser().then(t=>{if(!t)return Promise.reject();n(()=>mt.Authenticated)}).catch(()=>{n(()=>mt.NotAuthenticated)}))},[e]),{status:e,signUp:r,signIn:i,signOff:c,verifySignIn:o,verifyInvitation:s}},kt=()=>{const t=pt(),e=t.workspaceId,n=i(()=>["workspace",e],[e]),{data:r={status:o.NotInitialized,data:{}},set:s}=l(n),c=a(()=>{s({status:o.Loading,data:{}}),t.workspaces.byId(e).then(t=>s({data:t,status:o.Success})).catch(()=>s({status:o.Error,data:{}}))},[t,e]),f=a(n=>t.workspaces.createApiToken(e,n).then(({id:t,token:e})=>(s({status:workspaces.status,data:{...r,apiTokens:[...r.apiTokens,{id:t,description:n}]}}),e)),[t]),d=a(n=>t.workspaces.inviteUser(e,n),[t]);return u(()=>{e&&r.status===o.NotInitialized&&c()},[e,r]),{status:r.status,workspace:r.data,loadWorkspace:c,createApiToken:f,inviteUser:d}},bt=["workspaces"],wt=()=>{const t=pt(),{set:e,data:n={status:o.NotInitialized,data:[]}}=l(bt),r=a(()=>{e({status:o.Loading,data:[]}),t.workspaces.getAll().then(t=>e({status:o.Success,data:t})).catch(()=>e({status:o.Error,data:[]}))},[t]),i=a(r=>t.workspaces.create(r).then(t=>(e({status:n.status,data:[...n.data,t]}),t)),[t]);return u(()=>{n.status===o.NotInitialized&&r()},[n,r]),{status:n.status,workspaces:n.data,loadWorkspaces:r,createWorkspace:i}},Nt=t=>{const e=pt(),n=e.workspaceId,r=new URLSearchParams(t).toString();console.log("useQuery",t,r);const s=i(()=>[n,"queries",r,"status"],[n,r]),c=i(()=>[n,"queries",r,"data"],[n,r]),{data:f,set:d}=l(s,o.NotInitialized),{data:p,set:h}=l(c,[]),y=a(t=>{d(o.Loading),e.resources.get(t).then(t=>{d(o.Success),h(t)}).catch(()=>{d(o.Error)})},[e]);return u(()=>{console.log("useQuery effect",n,t,f),n&&t&&f===o.NotInitialized&&y(t)},[n,t,f]),{status:f,resources:p}},St=G((t,e,n)=>F(n=>n[t]===e[t]?e:n,n)),jt=t=>{const e=pt(),n=e.workspaceId,r=i(()=>["resources",n,"status",t],[n,t]),s=i(()=>["resources",n,"data"],[n]),{data:c,set:f}=l(r,o.NotInitialized),{data:d,set:p}=l(s,[]),h=i(()=>d.filter(e=>e.location===t),[d,t]),y=a(t=>{const n=d.find(e=>e.id===t);return n?Promise.resolve(n):e.resources.byId(t).then(t=>(p((e=[])=>St("id",t,e)),t))},[e,d,p]),g=a(()=>{f(o.Loading),e.resources.byLocation(t).then(t=>{f(o.Success),p((e=[])=>{const n=t.map(t=>t.id),r=e.filter(t=>!n.includes(t.id));return[...t,...r]})}).catch(()=>{f(o.Error)})},[e,t,f,p]),v=a(t=>e.resources.create({type:t.type,location:t.location,name:t.name,content:t.content}).then(t=>(p((e=[])=>[...e,t]),t)),[e,p]),m=a((t,n)=>e.resources.upload({location:t,file:n}).then(t=>(p((e=[])=>[...e,t]),t)),[e,p]),I=a(({location:t,name:n})=>e.resources.createDirectory({location:t,name:n}).then(t=>(p((e=[])=>[...e,t]),t)),[e,p]),A=a(t=>e.resources.remove(t).then(()=>p((e=[])=>ht("id",t,e))),[e,p]),k=a((t,n)=>e.resources.updateContent(t,n).then(t=>(p((e=[])=>St("id",t,e)),t)),[e,n,p]),b=a((t,n)=>e.resources.move(t,n).then(t=>(p((e=[])=>St("id",t,e)),t)),[e,n,p]),w=a((t,n)=>e.resources.rename(t,n).then(t=>(p((e=[])=>St("id",t,e)),t)),[e,n,p]);return u(()=>{n&&t&&c===o.NotInitialized&&g()},[n,t,c]),{status:c,resources:h,removeResource:A,createDocument:v,createDirectory:I,loadResource:y,updateResourceContent:k,moveResource:b,renameResource:w,uploadFile:m}},Et=t=>{const e=pt().workspaceId,n=i(()=>["resource",e,t,"status"],[t,e]),r=i(()=>["resource",e,t,"data"],[t,e]),{data:s=o.NotInitialized,set:c}=l(n),{data:f={},set:d}=l(r),{loadResource:p,removeResource:h,updateResourceContent:y,renameResource:g}=jt(),v=a(()=>{c(o.Loading),d({}),p(t).then(t=>{c(o.Success),d(t)}).catch(()=>{c(o.Error),d({})})},[t,p]),m=a(()=>h(t).then(()=>{c(o.NotInitialized),d({})}),[t,h]),I=a(e=>y(t,e).then(t=>d(t)),[t,y]),A=a(e=>g(t,e).then(t=>d(t)),[t,g]);return u(()=>{e&&t&&s===o.NotInitialized&&v()},[e,t,v]),{status:s,resource:f,loadResource:v,removeResource:m,updateResourceContent:I,renameResource:A}},zt=t=>{const{workspace:e}=kt();return e.resourceTemplates.find(e=>e.id===t)},Ot=["user","status"],Pt=["user","data"],xt=()=>{const t=pt(),{data:e=o.NotInitialized,set:n}=l(Ot),{data:r={},set:i}=l(Pt),s=a(e=>t.user.update(e).then(t=>(i(t),t)),[t]);return u(()=>{e===o.NotInitialized&&(n(()=>o.Loading),t.user.details().then(t=>{if(!t)return Promise.reject();i(t),n(()=>o.Success)}).catch(()=>{i({}),n(()=>o.Error)}))},[e]),{status:e,user:r,update:s}},Rt=()=>{const t=pt(),e=t.workspaceId,n=i(()=>["workspace",e,"users"],[e]),{data:r={status:o.NotInitialized,data:[]},set:s}=l(n),c=a(()=>{s({status:o.Loading,data:[]}),t.workspaces.users().then(t=>s({data:t,status:o.Success})).catch(()=>s({status:o.Error,data:[]}))},[t]);return u(()=>{e&&r.status===o.NotInitialized&&c()},[e,r]),{status:r.status,users:r.data,load:c}};export{o as AsyncStatus,mt as AuthenticationStatus,ft as Context,dt as WorkspaceProvider,vt as useApiTokens,At as useAuthentication,Nt as useQuery,Et as useResource,zt as useResourceTemplate,jt as useResources,pt as useSdk,xt as useUser,Rt as useUsers,kt as useWorkspace,wt as useWorkspaces};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/sdk-react",
|
|
3
3
|
"description": "Sofware Development Kit for interactive with our services in React",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.10",
|
|
5
5
|
"url": "git://github.com/ossy-se/packages/sdk-react",
|
|
6
6
|
"source": "src/index.js",
|
|
7
7
|
"main": "build/index.cjs.js",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"license": "MIT License",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "",
|
|
14
|
-
"build": "
|
|
14
|
+
"build": "rollup -c rollup.config.js",
|
|
15
15
|
"test": ""
|
|
16
16
|
},
|
|
17
17
|
"browserslist": {
|
|
@@ -28,24 +28,28 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"jwt-decode": "^3.1.2",
|
|
31
|
-
"ramda": "^0.
|
|
31
|
+
"ramda": "^0.32.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@babel/core": "^7.14.5",
|
|
35
35
|
"@babel/eslint-parser": "^7.15.8",
|
|
36
36
|
"@babel/preset-react": "^7.14.5",
|
|
37
|
-
"@rollup/plugin-commonjs": "^
|
|
38
|
-
"@rollup/plugin-node-resolve": "^
|
|
39
|
-
"babel-loader": "^
|
|
37
|
+
"@rollup/plugin-commonjs": "^28.0.9",
|
|
38
|
+
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
39
|
+
"babel-loader": "^10.0.0",
|
|
40
40
|
"react": "^17.0.2",
|
|
41
41
|
"react-dom": "^17.0.2",
|
|
42
|
-
"rollup": "^
|
|
42
|
+
"rollup": "^4.52.5",
|
|
43
43
|
"rollup-plugin-babel": "^4.4.0",
|
|
44
44
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
45
45
|
"rollup-plugin-terser": "^7.0.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"react": "
|
|
49
|
-
"react-dom": "
|
|
50
|
-
}
|
|
48
|
+
"react": ">=19.0.0 <20.0.0",
|
|
49
|
+
"react-dom": ">=19.0.0 <20.0.0"
|
|
50
|
+
},
|
|
51
|
+
"publishConfig": {
|
|
52
|
+
"access": "public"
|
|
53
|
+
},
|
|
54
|
+
"gitHead": "22ec3583362a630a927d9b7d0275787990062fdf"
|
|
51
55
|
}
|