@ossy/sdk-react 0.1.0 → 0.1.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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 0.1.1 (2025-10-31)
7
+
8
+ **Note:** Version bump only for package @ossy/sdk-react
9
+
10
+
11
+
12
+
13
+
6
14
  # 0.1.0 (2025-10-30)
7
15
 
8
16
 
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@ossy/sdk-react",
3
- "description": "Sofware Development Kit for interactive with our services in React",
4
- "version": "0.1.0",
3
+ "description": "Sofware Development Kit React",
4
+ "version": "0.1.1",
5
5
  "url": "git://github.com/ossy-se/packages/sdk-react",
6
- "source": "src/index.js",
7
- "module": "build/index.esm.js",
6
+ "source": "src/public.index.ts",
7
+ "module": "build/public.index.js",
8
+ "types": "build/public.index.d.ts",
9
+ "type": "module",
8
10
  "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
9
11
  "repository": {
10
12
  "type": "git",
@@ -33,15 +35,17 @@
33
35
  "ramda": "^0.32.0"
34
36
  },
35
37
  "devDependencies": {
36
- "@babel/core": "^7.14.5",
38
+ "@babel/cli": "^7.21.5",
39
+ "@babel/core": "^7.26.0",
37
40
  "@babel/eslint-parser": "^7.15.8",
38
- "@babel/preset-react": "^7.14.5",
39
- "babel-loader": "^10.0.0",
40
- "react": "^17.0.2",
41
- "react-dom": "^17.0.2",
42
- "rollup-plugin-babel": "^4.4.0"
41
+ "@babel/preset-env": "^7.26.0",
42
+ "@babel/preset-react": "^7.24.1",
43
+ "@babel/preset-typescript": "^7.26.0",
44
+ "@rollup/plugin-babel": "6.1.0",
45
+ "@types/ramda": "^0.31.1"
43
46
  },
44
47
  "peerDependencies": {
48
+ "@ossy/sdk": ">=0.1.0 <1.0.0",
45
49
  "react": ">=19.0.0 <20.0.0",
46
50
  "react-dom": ">=19.0.0 <20.0.0"
47
51
  },
@@ -49,5 +53,5 @@
49
53
  "access": "public",
50
54
  "registry": "https://registry.npmjs.org"
51
55
  },
52
- "gitHead": "286499c80fddc83845d05f46cb4f60fb7c17a7d3"
56
+ "gitHead": "84a2ce92ad013ccf992a009f84581880a7cb1acc"
53
57
  }
package/rollup.config.js CHANGED
@@ -1,26 +1,44 @@
1
- import babel from 'rollup-plugin-babel'
2
- import { nodeResolve } from '@rollup/plugin-node-resolve'
1
+ import babel from '@rollup/plugin-babel'
2
+ import { nodeResolve as resolveDependencies } from '@rollup/plugin-node-resolve'
3
+ import resolveCommonJsDependencies from '@rollup/plugin-commonjs'
3
4
  import removeOwnPeerDependencies from 'rollup-plugin-peer-deps-external'
4
- import commonjs from '@rollup/plugin-commonjs'
5
5
  import minifyJS from '@rollup/plugin-terser'
6
+ import typescript from '@rollup/plugin-typescript'
7
+ import preserveDirectives from "rollup-plugin-preserve-directives"
8
+ import { dts } from "rollup-plugin-dts"
6
9
  import pkg from './package.json'
7
10
 
8
- export default {
9
- input: pkg.source,
10
- output: [
11
- {
12
- file: pkg.module,
13
- format: 'esm'
14
- }
15
- ],
16
- plugins: [
17
- nodeResolve(),
18
- commonjs(),
19
- babel({
20
- exclude: ['**/node_modules/**/*'],
21
- presets: ['@babel/preset-react']
22
- }),
23
- removeOwnPeerDependencies(),
24
- minifyJS()
25
- ]
26
- }
11
+ export default [
12
+ {
13
+ input: pkg.source,
14
+ output: [
15
+ {
16
+ dir: 'build',
17
+ preserveModules: true,
18
+ format: 'esm'
19
+ }
20
+ ],
21
+ plugins: [
22
+ resolveCommonJsDependencies(),
23
+ resolveDependencies(),
24
+ removeOwnPeerDependencies(),
25
+ babel({
26
+ exclude: ['**/node_modules/**/*'],
27
+ presets: ['@babel/preset-react']
28
+ }),
29
+ minifyJS(),
30
+ preserveDirectives(),
31
+ typescript({
32
+ tsconfig: "./tsconfig.json",
33
+ outDir: 'build',
34
+ }),
35
+ ]
36
+ },
37
+ {
38
+ input: "build/types/public.index.d.ts",
39
+ output: [{ file: "build/public.index.d.ts", format: "es" }],
40
+ plugins: [
41
+ dts()
42
+ ],
43
+ },
44
+ ]
@@ -1,5 +1,3 @@
1
- // TODO: We should use Cache from @ossy-se/components when it becomes public
2
-
3
1
  import React, {
4
2
  createContext,
5
3
  useReducer,
@@ -8,18 +6,15 @@ import React, {
8
6
  } from 'react'
9
7
 
10
8
  const getInitialState = () => ({})
11
- export const CacheContext = createContext()
9
+ export const CacheContext = createContext<any>({})
12
10
 
13
11
  const Actions = {
14
12
  Set: 'SET'
15
13
  }
16
14
 
17
- // get: (path, state)
18
- // set: (path, value, state)
19
-
20
- const createReducer = ({ set, get }) => (
15
+ const createReducer = ({ set, get }: { set: any, get: any }) => (
21
16
  state = getInitialState(),
22
- action
17
+ action: any
23
18
  ) => {
24
19
  switch (action.type) {
25
20
 
@@ -42,18 +37,18 @@ const createReducer = ({ set, get }) => (
42
37
  }
43
38
  }
44
39
 
45
- export const createCache = ({ get: _get, set: _set }) => props => {
40
+ export const createCache = ({ get: _get, set: _set }: { get: any, set: any}) => (props: any) => {
46
41
 
47
42
  const [state, updateState] = useReducer(
48
43
  createReducer({ set: _set, get: _get }),
49
44
  getInitialState()
50
45
  )
51
46
 
52
- const set = useCallback(cachePath => data => {
47
+ const set = useCallback((cachePath: any) => (data: any) => {
53
48
  updateState({ type: Actions.Set, cachePath, data })
54
49
  }, [updateState])
55
50
 
56
- const get = useCallback(cachePath =>
51
+ const get = useCallback((cachePath: any) =>
57
52
  _get(cachePath, state),
58
53
  [state, _get]
59
54
  )
@@ -63,7 +58,7 @@ export const createCache = ({ get: _get, set: _set }) => props => {
63
58
  )
64
59
  }
65
60
 
66
- export const useCache = (cachePath, defaultValue) => {
61
+ export const useCache = (cachePath: any, defaultValue?: any) => {
67
62
  // TODO: Add default value to context here, otherwise it will be undefined in the set((data) => { ... }) function
68
63
  const { get, set } = useContext(CacheContext)
69
64
 
@@ -0,0 +1,27 @@
1
+ import React, { createContext, PropsWithChildren } from 'react'
2
+ import { createCache } from './Cache'
3
+ import { path, set, lensPath } from 'ramda'
4
+ import { type SDK } from '@ossy/sdk'
5
+
6
+ export const Context = createContext<Config>({} as Config)
7
+
8
+ const Cache = createCache({
9
+ get: path,
10
+ set: (path: any, value: any, data: any) => set(lensPath(path), value, data)
11
+ })
12
+
13
+ export interface Config {
14
+ sdk: SDK
15
+ }
16
+
17
+ export const WorkspaceProvider = ({ sdk, children }: PropsWithChildren<Config>) => {
18
+ return (
19
+ <Cache>
20
+ <Context.Provider value={{ sdk }}>
21
+ {children}
22
+ </Context.Provider>
23
+ </Cache>
24
+ )
25
+ }
26
+
27
+
@@ -0,0 +1,13 @@
1
+ export * from './asyncStatus'
2
+ export * from './useApiTokens'
3
+ export * from './useAuthentication'
4
+ export * from './useWorkspace'
5
+ export * from './useWorkspaces'
6
+ export * from './useQuery'
7
+ export * from './useResource'
8
+ export * from './useResourceTemplate'
9
+ export * from './useResources'
10
+ export * from './WorkspaceProvider'
11
+ export * from './useSdk'
12
+ export * from './useUser'
13
+ export * from './useUsers'
@@ -1,8 +1,8 @@
1
1
  import { useCallback, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { AsyncStatus } from './asyncStatus.js'
4
- import { useSdk } from './useSdk.js'
5
- import { removeBy } from './removeBy.js'
2
+ import { useCache } from './Cache'
3
+ import { AsyncStatus } from './asyncStatus'
4
+ import { useSdk } from './useSdk'
5
+ import { removeBy } from './removeBy'
6
6
 
7
7
  const statusPath = ['apiTokens', 'status']
8
8
  const dataPath = ['apiTokens', 'data']
@@ -21,24 +21,28 @@ export const useApiTokens = () => {
21
21
  } = useCache(dataPath)
22
22
 
23
23
  const createApiToken = useCallback(
24
- description => sdk.apiTokens.create(description)
25
- .then(newToken => {
26
- setTokens(tokens => [...tokens, newToken])
27
- return newToken
24
+ (token: {
25
+ name: string;
26
+ description: string;
27
+ expiresAt: string;
28
+ }) => sdk.apiTokens.create(token)
29
+ .then((token: any) => {
30
+ setTokens((tokens: any[]) => [...tokens, token])
31
+ return token
28
32
  }),
29
33
  [sdk]
30
34
  )
31
35
 
32
36
  const invalidateApiToken = useCallback(
33
- tokenId => sdk.apiTokens.invalidate(tokenId)
34
- .then(() => setTokens(tokens => removeBy('id', tokenId, tokens))),
37
+ (id: string) => sdk.apiTokens.invalidate({ id })
38
+ .then(() => setTokens((tokens: any[]) => removeBy('id', id, tokens))),
35
39
  [sdk]
36
40
  )
37
41
 
38
42
  const loadApiTokens = useCallback(() => {
39
43
  setStatus(AsyncStatus.Loading)
40
- sdk.apiTokens.getAll()
41
- .then(tokens => {
44
+ sdk.apiTokens.list()
45
+ .then((tokens: any[]) => {
42
46
  setTokens(tokens)
43
47
  setStatus(AsyncStatus.Success)
44
48
  })
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { useSdk } from './useSdk'
4
4
 
5
5
  export const AuthenticationStatus = {
6
6
  AuthenticationError: 'AuthenticationError',
@@ -22,11 +22,11 @@ export const useAuthentication = () => {
22
22
  } = useCache(statusPath)
23
23
 
24
24
  const signUp = useCallback(
25
- email => {
25
+ (email: string) => {
26
26
  setStatus(() => AuthenticationStatus.Verifying)
27
- return sdk.auth.signUp(email)
27
+ return sdk.auth.signUp({ email })
28
28
  .then(() => setStatus(AuthenticationStatus.VerifySignIn))
29
- .catch(error => {
29
+ .catch((error: any) => {
30
30
  setStatus(AuthenticationStatus.AuthenticationError)
31
31
  return Promise.reject(error)
32
32
  })
@@ -35,11 +35,11 @@ export const useAuthentication = () => {
35
35
  )
36
36
 
37
37
  const signIn = useCallback(
38
- email => {
38
+ (email: any) => {
39
39
  setStatus(() => AuthenticationStatus.Verifying)
40
40
  return sdk.auth.signIn(email)
41
41
  .then(() => setStatus(AuthenticationStatus.VerifySignIn))
42
- .catch((error) => {
42
+ .catch((error: any) => {
43
43
  setStatus(AuthenticationStatus.AuthenticationError)
44
44
  return Promise.reject(error)
45
45
  })
@@ -48,11 +48,11 @@ export const useAuthentication = () => {
48
48
  )
49
49
 
50
50
  const verifySignIn = useCallback(
51
- token => {
51
+ (token: string) => {
52
52
  setStatus(() => AuthenticationStatus.Verifying)
53
- return sdk.auth.verifySignIn(token)
53
+ return sdk.auth.verifySignIn({ token })
54
54
  .then(() => setStatus(AuthenticationStatus.Authenticated))
55
- .catch((error) => {
55
+ .catch((error: any) => {
56
56
  setStatus(AuthenticationStatus.AuthenticationError)
57
57
  return Promise.reject(error)
58
58
  })
@@ -61,11 +61,11 @@ export const useAuthentication = () => {
61
61
  )
62
62
 
63
63
  const verifyInvitation = useCallback(
64
- (workspaceId, token) => {
64
+ (workspaceId: string, token: string) => {
65
65
  setStatus(() => AuthenticationStatus.Verifying)
66
- return sdk.auth.verifyInvitation(workspaceId, token)
66
+ return sdk.auth.verifyInvitation({ workspaceId, token})
67
67
  .then(() => setStatus(AuthenticationStatus.Authenticated))
68
- .catch((error) => {
68
+ .catch((error: any) => {
69
69
  setStatus(AuthenticationStatus.AuthenticationError)
70
70
  return Promise.reject(error)
71
71
  })
@@ -84,7 +84,7 @@ export const useAuthentication = () => {
84
84
  setStatus(() => AuthenticationStatus.Verifying)
85
85
 
86
86
  sdk.auth.getAuthenticatedUser()
87
- .then(user => {
87
+ .then((user: any) => {
88
88
  if (!user) return Promise.reject()
89
89
  setStatus(() => AuthenticationStatus.Authenticated)
90
90
  })
@@ -1,13 +1,12 @@
1
1
  import { useCallback, useMemo, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { AsyncStatus } from './asyncStatus.js'
4
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { AsyncStatus } from './asyncStatus'
4
+ import { useSdk } from './useSdk'
5
5
 
6
- export const useQuery = incomingQuery => {
6
+ export const useQuery = (incomingQuery: any) => {
7
7
  const sdk = useSdk()
8
8
  const workspaceId = sdk.workspaceId
9
9
  const queryString = new URLSearchParams(incomingQuery).toString()
10
- console.log('useQuery', incomingQuery, queryString)
11
10
 
12
11
  const statusCachePath = useMemo(
13
12
  () => [workspaceId, 'queries', queryString, 'status'],
@@ -29,18 +28,17 @@ export const useQuery = incomingQuery => {
29
28
  set: setResources
30
29
  } = useCache(dataCachePath, [])
31
30
 
32
- const loadResources = useCallback(query => {
31
+ const loadResources = useCallback((query: any) => {
33
32
  setStatus(AsyncStatus.Loading)
34
33
  sdk.resources.get(query)
35
- .then(matchedResources => {
34
+ .then((resources: any) => {
36
35
  setStatus(AsyncStatus.Success)
37
- setResources(matchedResources)
36
+ setResources(resources)
38
37
  })
39
38
  .catch(() => { setStatus(AsyncStatus.Error) })
40
39
  }, [sdk])
41
40
 
42
41
  useEffect(() => {
43
- console.log('useQuery effect', workspaceId, incomingQuery, status)
44
42
  if (!workspaceId) return
45
43
  if (!incomingQuery) return
46
44
  if (status !== AsyncStatus.NotInitialized) return
@@ -1,21 +1,21 @@
1
1
  import { useCallback, useMemo, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { AsyncStatus } from './asyncStatus.js'
4
- import { useResources } from './useResources.js'
5
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { AsyncStatus } from './asyncStatus'
4
+ import { useResources } from './useResources'
5
+ import { useSdk } from './useSdk'
6
6
 
7
- export const useResource = (resourceId) => {
7
+ export const useResource = (id: string) => {
8
8
  const sdk = useSdk()
9
9
  const workspaceId = sdk.workspaceId
10
10
 
11
11
  const statusCachePath = useMemo(
12
- () => ['resource', workspaceId, resourceId, 'status'],
13
- [resourceId, workspaceId]
12
+ () => ['resource', workspaceId, id, 'status'],
13
+ [id, workspaceId]
14
14
  )
15
15
 
16
16
  const dataCachePath = useMemo(
17
- () => ['resource', workspaceId, resourceId, 'data'],
18
- [resourceId, workspaceId]
17
+ () => ['resource', workspaceId, id, 'data'],
18
+ [id, workspaceId]
19
19
  )
20
20
 
21
21
  const {
@@ -38,8 +38,8 @@ export const useResource = (resourceId) => {
38
38
  const loadResource = useCallback(() => {
39
39
  setStatus(AsyncStatus.Loading)
40
40
  setResource({})
41
- _loadResource(resourceId)
42
- .then(resource => {
41
+ _loadResource(id)
42
+ .then((resource: any) => {
43
43
  setStatus(AsyncStatus.Success)
44
44
  setResource(resource)
45
45
  })
@@ -47,38 +47,38 @@ export const useResource = (resourceId) => {
47
47
  setStatus(AsyncStatus.Error)
48
48
  setResource({})
49
49
  })
50
- }, [resourceId, _loadResource])
50
+ }, [id, _loadResource])
51
51
 
52
52
  const removeResource = useCallback(
53
- () => _removeResource(resourceId)
53
+ () => _removeResource(id)
54
54
  .then(() => {
55
55
  setStatus(AsyncStatus.NotInitialized)
56
56
  setResource({})
57
57
  }),
58
- [resourceId, _removeResource]
58
+ [id, _removeResource]
59
59
  )
60
60
 
61
61
  const updateResourceContent = useCallback(
62
- resourceContent => _updateResourceContent(resourceId, resourceContent)
63
- .then(updatedResource => setResource(updatedResource)),
64
- [resourceId, _updateResourceContent]
62
+ (content: any) => _updateResourceContent(id, content)
63
+ .then((resource: any) => setResource(resource)),
64
+ [id, _updateResourceContent]
65
65
  )
66
66
 
67
67
  const renameResource = useCallback(
68
- newName => _renameResource(resourceId, newName)
69
- .then(updatedResource => setResource(updatedResource)),
70
- [resourceId, _renameResource]
68
+ (name: string) => _renameResource(id, name)
69
+ .then((resource: any) => setResource(resource)),
70
+ [id, _renameResource]
71
71
  )
72
72
 
73
73
  useEffect(() => {
74
74
 
75
75
  if (!workspaceId) return
76
- if (!resourceId) return
76
+ if (!id) return
77
77
  if (status !== AsyncStatus.NotInitialized) return
78
78
 
79
79
  loadResource()
80
80
 
81
- }, [workspaceId, resourceId, loadResource])
81
+ }, [workspaceId, id, loadResource])
82
82
 
83
83
  return {
84
84
  status,
@@ -0,0 +1,8 @@
1
+ import { useWorkspace } from './useWorkspace'
2
+
3
+ export const useResourceTemplate = (id: string) => {
4
+ const { workspace } = useWorkspace()
5
+ // TODO: workspace.resourceTemplates might not exist yet
6
+ const template = workspace.resourceTemplates.find((template: { id: string }) => template.id === id)
7
+ return template
8
+ }
@@ -1,11 +1,11 @@
1
1
  import { useCallback, useMemo, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { removeBy } from './removeBy.js'
4
- import { replaceBy } from './replaceBy.js'
5
- import { AsyncStatus } from './asyncStatus.js'
6
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { removeBy } from './removeBy'
4
+ import { replaceBy } from './replaceBy'
5
+ import { AsyncStatus } from './asyncStatus'
6
+ import { useSdk } from './useSdk'
7
7
 
8
- export const useResources = (location) => {
8
+ export const useResources = (location?: string) => {
9
9
  const sdk = useSdk()
10
10
  const workspaceId = sdk.workspaceId
11
11
 
@@ -30,19 +30,19 @@ export const useResources = (location) => {
30
30
  } = useCache(dataCachePath, [])
31
31
 
32
32
  const locationSpecificResources = useMemo(
33
- () => resources.filter(resource => resource.location === location),
33
+ () => resources.filter((resource: { location: string }) => resource.location === location),
34
34
  [resources, location]
35
35
  )
36
36
 
37
37
  const loadResource = useCallback(
38
- resourceId => {
39
- const cachedResource = resources.find(resource => resource.id === resourceId)
38
+ (id: string) => {
39
+ const cachedResource = resources.find((resource: { id: string }) => resource.id === id)
40
40
  return !!cachedResource
41
41
  ? Promise.resolve(cachedResource)
42
- : sdk.resources.byId(resourceId)
43
- .then(requestedResource => {
44
- setResources((resources = []) => replaceBy('id', requestedResource, resources))
45
- return requestedResource
42
+ : sdk.resources.get({ id })
43
+ .then((resource: any) => {
44
+ setResources((resources = []) => replaceBy('id', resource, resources))
45
+ return resource
46
46
  })
47
47
  },
48
48
  [sdk, resources, setResources]
@@ -50,15 +50,15 @@ export const useResources = (location) => {
50
50
 
51
51
  const loadResources = useCallback(() => {
52
52
  setStatus(AsyncStatus.Loading)
53
- sdk.resources.byLocation(location)
54
- .then(requestedResources => {
53
+ sdk.resources.list({ location })
54
+ .then((requestedResources: any) => {
55
55
  setStatus(AsyncStatus.Success)
56
56
  // TODO: Duplicated resources can occur when you move a resource into a directory
57
57
  // then navigate to that directory, causing it to load the recently moved resource from BE into the resources list
58
58
  // Should probably use another data structure that ensures uniqueness.
59
59
  // temp fix is the resourcesWithStaleResourcesRemoved
60
- setResources((resources = []) => {
61
- const requestedResourcesIds = requestedResources.map(resource => resource.id)
60
+ setResources((resources: any[] = []) => {
61
+ const requestedResourcesIds = requestedResources.map((resource: { id: string }) => resource.id)
62
62
 
63
63
  const resourcesWithStaleResourcesRemoved = resources.filter(
64
64
  resource => !requestedResourcesIds.includes(resource.id)
@@ -71,48 +71,48 @@ export const useResources = (location) => {
71
71
  }, [sdk, location, setStatus, setResources])
72
72
 
73
73
  const createDocument = useCallback(
74
- document => sdk.resources.create({
74
+ (document: any) => sdk.resources.create({
75
75
  type: document.type,
76
76
  location: document.location,
77
77
  name: document.name,
78
78
  content: document.content
79
79
  })
80
- .then(newResource => {
81
- setResources((resources = []) => [...resources, newResource])
82
- return newResource
80
+ .then((resource: any) => {
81
+ setResources((resources = []) => [...resources, resource])
82
+ return resource
83
83
  }),
84
84
  [sdk, setResources]
85
85
  )
86
86
 
87
87
  const uploadFile = useCallback(
88
- (location, file) => sdk.resources.upload({ location, file })
89
- .then(newResource => {
90
- setResources((resources = []) => [...resources, newResource])
91
- return newResource
88
+ (location: string, file: File) => sdk.resources.upload({ location, file })
89
+ .then((resource: any) => {
90
+ setResources((resources = []) => [...resources, resource])
91
+ return resource
92
92
  }),
93
93
  [sdk, setResources]
94
94
  )
95
95
 
96
96
  const createDirectory = useCallback(
97
- ({ location, name }) => sdk.resources.createDirectory({ location, name })
98
- .then(newResource => {
99
- setResources((resources = []) => [...resources, newResource])
100
- return newResource
97
+ ({ location, name }: { location: string, name: string }) => sdk.resources.createDirectory({ type: 'directory', location, name })
98
+ .then((resource: any) => {
99
+ setResources((resources = []) => [...resources, resource])
100
+ return resource
101
101
  }),
102
102
  [sdk, setResources]
103
103
  )
104
104
 
105
105
  const removeResource = useCallback(
106
- resourceId => sdk.resources.remove(resourceId)
107
- .then(() => setResources((resources = []) => removeBy('id', resourceId, resources))),
106
+ (id: string) => sdk.resources.remove({ id })
107
+ .then(() => setResources((resources = []) => removeBy('id', id, resources))),
108
108
  [sdk, setResources]
109
109
  )
110
110
 
111
111
  const updateResourceContent = useCallback(
112
- (resourceId, content) => sdk.resources.updateContent(resourceId, content)
113
- .then(updatedResource => {
114
- setResources((resources = []) => replaceBy('id', updatedResource, resources))
115
- return updatedResource
112
+ (id: string, content: any) => sdk.resources.updateContent({ id, content})
113
+ .then((resource: any) => {
114
+ setResources((resources = []) => replaceBy('id', resource, resources))
115
+ return resource
116
116
  }),
117
117
  [sdk, workspaceId, setResources]
118
118
  )
@@ -120,10 +120,10 @@ export const useResources = (location) => {
120
120
  const moveResource = useCallback(
121
121
  // TODO: how should we add this to the new location in cache?
122
122
  // TODO: if recource is a direcotry, how should we move the nested resources from cache?
123
- (resourceId, newLocation) => sdk.resources.move(resourceId, newLocation)
124
- .then(movedResource => {
125
- setResources((resources = []) => replaceBy('id', movedResource, resources))
126
- return movedResource
123
+ (id: string, target: string) => sdk.resources.move({ id, target })
124
+ .then((resource: string) => {
125
+ setResources((resources = []) => replaceBy('id', resource, resources))
126
+ return resource
127
127
  }),
128
128
  [sdk, workspaceId, setResources]
129
129
  )
@@ -131,10 +131,10 @@ export const useResources = (location) => {
131
131
  const renameResource = useCallback(
132
132
  // TODO: how should we update the cache for individual resources
133
133
  // mabye by making this an internal function and only use it through useResource?
134
- (resourceId, newName) => sdk.resources.rename(resourceId, newName)
135
- .then(updatedResource => {
136
- setResources((resources = []) => replaceBy('id', updatedResource, resources))
137
- return updatedResource
134
+ (id: string, name: string) => sdk.resources.rename({ id, name })
135
+ .then((resource: any) => {
136
+ setResources((resources = []) => replaceBy('id', resource, resources))
137
+ return resource
138
138
  }),
139
139
  [sdk, workspaceId, setResources]
140
140
  )
@@ -1,5 +1,5 @@
1
1
  import { useContext } from 'react'
2
- import { Context } from './WorkspaceProvider.jsx'
2
+ import { Context } from './WorkspaceProvider'
3
3
 
4
4
  export function useSdk() {
5
5
  return useContext(Context).sdk
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { useSdk } from './useSdk.js'
4
- import { AsyncStatus } from './asyncStatus.js'
2
+ import { useCache } from './Cache'
3
+ import { useSdk } from './useSdk'
4
+ import { AsyncStatus } from './asyncStatus'
5
5
 
6
6
  const statusPath = ['user', 'status']
7
7
  const userPath = ['user', 'data']
@@ -20,9 +20,9 @@ export const useUser = () => {
20
20
  } = useCache(userPath)
21
21
 
22
22
  const update = useCallback(
23
- user => {
24
- return sdk.user.update(user)
25
- .then((updatedUser) => {
23
+ (user: any) => {
24
+ return sdk.currentUser.update(user)
25
+ .then((updatedUser: any) => {
26
26
  setUser(updatedUser)
27
27
  return updatedUser
28
28
  })
@@ -34,8 +34,8 @@ export const useUser = () => {
34
34
  if (status !== AsyncStatus.NotInitialized) return
35
35
  setStatus(() => AsyncStatus.Loading)
36
36
 
37
- sdk.user.details()
38
- .then(user => {
37
+ sdk.currentUser.get()
38
+ .then((user: any) => {
39
39
  if (!user) return Promise.reject()
40
40
  setUser(user)
41
41
  setStatus(() => AsyncStatus.Success)
@@ -45,7 +45,7 @@ export const useUser = () => {
45
45
  setStatus(() => AsyncStatus.Error)
46
46
  })
47
47
 
48
- }, [status])
48
+ }, [status, sdk])
49
49
 
50
50
  return {
51
51
  status,
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect, useMemo } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { AsyncStatus } from './asyncStatus.js'
4
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { AsyncStatus } from './asyncStatus'
4
+ import { useSdk } from './useSdk'
5
5
 
6
6
  export const useUsers = () => {
7
7
  const sdk = useSdk()
@@ -16,8 +16,8 @@ export const useUsers = () => {
16
16
  const load = useCallback(() => {
17
17
  setUsers({ status: AsyncStatus.Loading, data: [] })
18
18
 
19
- sdk.workspaces.users()
20
- .then(users => setUsers({ data: users, status: AsyncStatus.Success }))
19
+ sdk.users.list()
20
+ .then((users: any[]) => setUsers({ data: users, status: AsyncStatus.Success }))
21
21
  .catch(() => setUsers({ status: AsyncStatus.Error, data: [] }))
22
22
 
23
23
  }, [sdk])
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect, useMemo } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { AsyncStatus } from './asyncStatus.js'
4
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { AsyncStatus } from './asyncStatus'
4
+ import { useSdk } from './useSdk'
5
5
 
6
6
  export const useWorkspace = () => {
7
7
  const sdk = useSdk()
@@ -15,17 +15,17 @@ export const useWorkspace = () => {
15
15
 
16
16
  const loadWorkspace = useCallback(() => {
17
17
  setWorkspace({ status: AsyncStatus.Loading, data: {} })
18
- sdk.workspaces.byId(workspaceId)
19
- .then(workspace => setWorkspace({ data: workspace, status: AsyncStatus.Success }))
18
+ sdk.workspaces.current()
19
+ .then((workspace: any) => setWorkspace({ data: workspace, status: AsyncStatus.Success }))
20
20
  .catch(() => setWorkspace({ status: AsyncStatus.Error, data: {} }))
21
21
  }, [sdk, workspaceId])
22
22
 
23
23
  const createApiToken = useCallback(
24
- description => sdk.workspaces.createApiToken(workspaceId, description)
25
- .then(({ id, token }) => {
24
+ (description: string) => sdk.workspaces.createApiToken({ description })
25
+ .then(({ id, token }: { id: string, token: string }) => {
26
26
 
27
27
  setWorkspace({
28
- status: workspaces.status,
28
+ status: workspace.status,
29
29
  data: {
30
30
  ...workspace,
31
31
  apiTokens: [...workspace.apiTokens, { id, description }]
@@ -38,7 +38,7 @@ export const useWorkspace = () => {
38
38
  )
39
39
 
40
40
  const inviteUser = useCallback(
41
- email => sdk.workspaces.inviteUser(workspaceId, email),
41
+ (email: string) => sdk.workspaces.inviteUser({ email }),
42
42
  [sdk]
43
43
  )
44
44
 
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect } from 'react'
2
- import { useCache } from './Cache.jsx'
3
- import { AsyncStatus } from './asyncStatus.js'
4
- import { useSdk } from './useSdk.js'
2
+ import { useCache } from './Cache'
3
+ import { AsyncStatus } from './asyncStatus'
4
+ import { useSdk } from './useSdk'
5
5
 
6
6
  const cachePath = ['workspaces']
7
7
 
@@ -15,14 +15,14 @@ export const useWorkspaces = () => {
15
15
 
16
16
  const loadWorkspaces = useCallback(() => {
17
17
  setWorkspaces({ status: AsyncStatus.Loading, data: [] })
18
- sdk.workspaces.getAll()
19
- .then(workspaces => setWorkspaces({ status: AsyncStatus.Success, data: workspaces }))
18
+ sdk.workspaces.list()
19
+ .then((workspaces: any[]) => setWorkspaces({ status: AsyncStatus.Success, data: workspaces }))
20
20
  .catch(() => setWorkspaces({ status: AsyncStatus.Error, data: [] }))
21
21
  }, [sdk])
22
22
 
23
23
  const createWorkspace = useCallback(
24
- workspaceName => sdk.workspaces.create(workspaceName)
25
- .then(workspace => {
24
+ (name: string) => sdk.workspaces.create({ name })
25
+ .then((workspace: any) => {
26
26
 
27
27
  setWorkspaces({
28
28
  status: workspaces.status,
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es5",
4
+ "lib": ["dom", "dom.iterable", "esnext"],
5
+ "allowJs": true,
6
+ "skipLibCheck": true,
7
+ "strict": true,
8
+ "forceConsistentCasingInFileNames": true,
9
+ "esModuleInterop": true,
10
+ "module": "esnext",
11
+ "moduleResolution": "node",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "jsx": "react",
15
+ "incremental": false,
16
+ "declaration": true,
17
+ "declarationDir": "./build/types"
18
+ },
19
+ "exclude": [
20
+ "build",
21
+ "node_modules",
22
+ "src/**/*.test.tsx",
23
+ "src/**/*.stories.tsx",
24
+ "rollup.config.js",
25
+ "src/data.mock.ts"
26
+ ]
27
+ }
@@ -1,22 +0,0 @@
1
- import React, { createContext } from 'react'
2
- import { createCache } from './Cache.jsx' // TODO: We should use Cache from @ossy-se/components when it becomes public
3
- import { path, set, lensPath } from 'ramda' // TODO: not be dependent on ramda
4
-
5
- export const Context = createContext({})
6
-
7
- const Cache = createCache({
8
- get: path,
9
- set: (path, value, data) => set(lensPath(path), value, data)
10
- })
11
-
12
- export const WorkspaceProvider = ({ sdk, children }) => {
13
- return (
14
- <Cache>
15
- <Context.Provider value={{ sdk }}>
16
- {children}
17
- </Context.Provider>
18
- </Cache>
19
- )
20
- }
21
-
22
-
package/src/index.js DELETED
@@ -1,13 +0,0 @@
1
- export * from './asyncStatus.js'
2
- export * from './useApiTokens.js'
3
- export * from './useAuthentication.js'
4
- export * from './useWorkspace.js'
5
- export * from './useWorkspaces.js'
6
- export * from './useQuery.js'
7
- export * from './useResource.js'
8
- export * from './useResourceTemplate.js'
9
- export * from './useResources.js'
10
- export * from './WorkspaceProvider.jsx'
11
- export * from './useSdk.js'
12
- export * from './useUser.js'
13
- export * from './useUsers.js'
@@ -1,8 +0,0 @@
1
- import { useWorkspace } from './useWorkspace.js'
2
-
3
- export const useResourceTemplate = templateId => {
4
- const { workspace } = useWorkspace()
5
- // TODO: workspace.resourceTemplates might not exist yet
6
- const template = workspace.resourceTemplates.find(template => template.id === templateId)
7
- return template
8
- }
File without changes