@ossy/sdk-react 0.1.4 → 0.1.6

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.
Files changed (102) hide show
  1. package/build/node_modules/ramda/es/always.js +1 -0
  2. package/build/node_modules/ramda/es/assocPath.js +1 -0
  3. package/build/node_modules/ramda/es/curry.js +1 -0
  4. package/build/node_modules/ramda/es/curryN.js +1 -0
  5. package/build/node_modules/ramda/es/equals.js +1 -0
  6. package/build/node_modules/ramda/es/findIndex.js +1 -0
  7. package/build/node_modules/ramda/es/internal/_arity.js +1 -0
  8. package/build/node_modules/ramda/es/internal/_arrayFromIterator.js +1 -0
  9. package/build/node_modules/ramda/es/internal/_arrayReduce.js +1 -0
  10. package/build/node_modules/ramda/es/internal/_assoc.js +1 -0
  11. package/build/node_modules/ramda/es/internal/_curry1.js +1 -0
  12. package/build/node_modules/ramda/es/internal/_curry2.js +1 -0
  13. package/build/node_modules/ramda/es/internal/_curry3.js +1 -0
  14. package/build/node_modules/ramda/es/internal/_curryN.js +1 -0
  15. package/build/node_modules/ramda/es/internal/_dispatchable.js +1 -0
  16. package/build/node_modules/ramda/es/internal/_equals.js +1 -0
  17. package/build/node_modules/ramda/es/internal/_functionName.js +1 -0
  18. package/build/node_modules/ramda/es/internal/_has.js +1 -0
  19. package/build/node_modules/ramda/es/internal/_includesWith.js +1 -0
  20. package/build/node_modules/ramda/es/internal/_isArguments.js +1 -0
  21. package/build/node_modules/ramda/es/internal/_isArray.js +1 -0
  22. package/build/node_modules/ramda/es/internal/_isInteger.js +1 -0
  23. package/build/node_modules/ramda/es/internal/_isPlaceholder.js +1 -0
  24. package/build/node_modules/ramda/es/internal/_isTransformer.js +1 -0
  25. package/build/node_modules/ramda/es/internal/_map.js +1 -0
  26. package/build/node_modules/ramda/es/internal/_nth.js +1 -0
  27. package/build/node_modules/ramda/es/internal/_objectIs.js +1 -0
  28. package/build/node_modules/ramda/es/internal/_path.js +1 -0
  29. package/build/node_modules/ramda/es/internal/_prop.js +1 -0
  30. package/build/node_modules/ramda/es/internal/_reduced.js +1 -0
  31. package/build/node_modules/ramda/es/internal/_xfBase.js +1 -0
  32. package/build/node_modules/ramda/es/internal/_xfindIndex.js +1 -0
  33. package/build/node_modules/ramda/es/internal/_xmap.js +1 -0
  34. package/build/node_modules/ramda/es/isNil.js +1 -0
  35. package/build/node_modules/ramda/es/keys.js +1 -0
  36. package/build/node_modules/ramda/es/lens.js +1 -0
  37. package/build/node_modules/ramda/es/lensPath.js +1 -0
  38. package/build/node_modules/ramda/es/map.js +1 -0
  39. package/build/node_modules/ramda/es/over.js +1 -0
  40. package/build/node_modules/ramda/es/path.js +1 -0
  41. package/build/node_modules/ramda/es/prop.js +1 -0
  42. package/build/node_modules/ramda/es/propEq.js +1 -0
  43. package/build/node_modules/ramda/es/remove.js +1 -0
  44. package/build/node_modules/ramda/es/set.js +1 -0
  45. package/build/node_modules/ramda/es/type.js +1 -0
  46. package/build/node_modules/tslib/tslib.es6.js +1 -0
  47. package/build/public.index.d.ts +108 -0
  48. package/build/sdk-react/src/Cache.js +1 -0
  49. package/build/sdk-react/src/WorkspaceProvider.js +1 -0
  50. package/build/sdk-react/src/asyncStatus.js +1 -0
  51. package/build/sdk-react/src/public.index.js +1 -0
  52. package/build/sdk-react/src/removeBy.js +1 -0
  53. package/build/sdk-react/src/replaceBy.js +1 -0
  54. package/build/sdk-react/src/useApiTokens.js +1 -0
  55. package/build/sdk-react/src/useAuthentication.js +1 -0
  56. package/build/sdk-react/src/useQuery.js +1 -0
  57. package/build/sdk-react/src/useResource.js +1 -0
  58. package/build/sdk-react/src/useResourceTemplate.js +1 -0
  59. package/build/sdk-react/src/useResources.js +1 -0
  60. package/build/sdk-react/src/useSdk.js +1 -0
  61. package/build/sdk-react/src/useUser.js +1 -0
  62. package/build/sdk-react/src/useUsers.js +1 -0
  63. package/build/sdk-react/src/useWorkspace.js +1 -0
  64. package/build/sdk-react/src/useWorkspaces.js +1 -0
  65. package/build/types/Cache.d.ts +10 -0
  66. package/build/types/WorkspaceProvider.d.ts +7 -0
  67. package/build/types/asyncStatus.d.ts +6 -0
  68. package/build/types/public.index.d.ts +13 -0
  69. package/build/types/removeBy.d.ts +1 -0
  70. package/build/types/replaceBy.d.ts +1 -0
  71. package/build/types/useApiTokens.d.ts +10 -0
  72. package/build/types/useAuthentication.d.ts +16 -0
  73. package/build/types/useQuery.d.ts +4 -0
  74. package/build/types/useResource.d.ts +8 -0
  75. package/build/types/useResourceTemplate.d.ts +1 -0
  76. package/build/types/useResources.d.ts +15 -0
  77. package/build/types/useSdk.d.ts +1 -0
  78. package/build/types/useUser.d.ts +5 -0
  79. package/build/types/useUsers.d.ts +5 -0
  80. package/build/types/useWorkspace.d.ts +7 -0
  81. package/build/types/useWorkspaces.d.ts +6 -0
  82. package/package.json +6 -2
  83. package/CHANGELOG.md +0 -166
  84. package/rollup.config.js +0 -44
  85. package/src/Cache.tsx +0 -76
  86. package/src/WorkspaceProvider.tsx +0 -27
  87. package/src/asyncStatus.ts +0 -6
  88. package/src/public.index.ts +0 -13
  89. package/src/removeBy.js +0 -7
  90. package/src/replaceBy.js +0 -6
  91. package/src/useApiTokens.ts +0 -63
  92. package/src/useAuthentication.ts +0 -105
  93. package/src/useQuery.ts +0 -49
  94. package/src/useResource.ts +0 -91
  95. package/src/useResourceTemplate.ts +0 -8
  96. package/src/useResources.ts +0 -163
  97. package/src/useSdk.ts +0 -7
  98. package/src/useUser.ts +0 -55
  99. package/src/useUsers.ts +0 -38
  100. package/src/useWorkspace.ts +0 -67
  101. package/src/useWorkspaces.ts +0 -49
  102. package/tsconfig.json +0 -27
@@ -1,163 +0,0 @@
1
- import { useCallback, useMemo, useEffect } from 'react'
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
-
8
- export const useResources = (location?: string) => {
9
- const sdk = useSdk()
10
- const workspaceId = sdk.workspaceId
11
-
12
- const statusCachePath = useMemo(
13
- () => ['resources', workspaceId, 'status', location],
14
- [workspaceId, location]
15
- )
16
-
17
- const dataCachePath = useMemo(
18
- () => ['resources', workspaceId, 'data'],
19
- [workspaceId]
20
- )
21
-
22
- const {
23
- data: status,
24
- set: setStatus
25
- } = useCache(statusCachePath, AsyncStatus.NotInitialized)
26
-
27
- const {
28
- data: resources,
29
- set: setResources
30
- } = useCache(dataCachePath, [])
31
-
32
- const locationSpecificResources = useMemo(
33
- () => resources.filter((resource: { location: string }) => resource.location === location),
34
- [resources, location]
35
- )
36
-
37
- const loadResource = useCallback(
38
- (id: string) => {
39
- const cachedResource = resources.find((resource: { id: string }) => resource.id === id)
40
- return !!cachedResource
41
- ? Promise.resolve(cachedResource)
42
- : sdk.resources.get({ id })
43
- .then((resource: any) => {
44
- setResources((resources = []) => replaceBy('id', resource, resources))
45
- return resource
46
- })
47
- },
48
- [sdk, resources, setResources]
49
- )
50
-
51
- const loadResources = useCallback(() => {
52
- setStatus(AsyncStatus.Loading)
53
- sdk.resources.list({ location })
54
- .then((requestedResources: any) => {
55
- setStatus(AsyncStatus.Success)
56
- // TODO: Duplicated resources can occur when you move a resource into a directory
57
- // then navigate to that directory, causing it to load the recently moved resource from BE into the resources list
58
- // Should probably use another data structure that ensures uniqueness.
59
- // temp fix is the resourcesWithStaleResourcesRemoved
60
- setResources((resources: any[] = []) => {
61
- const requestedResourcesIds = requestedResources.map((resource: { id: string }) => resource.id)
62
-
63
- const resourcesWithStaleResourcesRemoved = resources.filter(
64
- resource => !requestedResourcesIds.includes(resource.id)
65
- )
66
-
67
- return [...requestedResources, ...resourcesWithStaleResourcesRemoved]
68
- })
69
- })
70
- .catch(() => { setStatus(AsyncStatus.Error) })
71
- }, [sdk, location, setStatus, setResources])
72
-
73
- const createDocument = useCallback(
74
- (document: any) => sdk.resources.create({
75
- type: document.type,
76
- location: document.location,
77
- name: document.name,
78
- content: document.content
79
- })
80
- .then((resource: any) => {
81
- setResources((resources = []) => [...resources, resource])
82
- return resource
83
- }),
84
- [sdk, setResources]
85
- )
86
-
87
- const uploadFile = useCallback(
88
- (location: string, file: File) => sdk.resources.upload({ location, file })
89
- .then((resource: any) => {
90
- setResources((resources = []) => [...resources, resource])
91
- return resource
92
- }),
93
- [sdk, setResources]
94
- )
95
-
96
- const createDirectory = useCallback(
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
- }),
102
- [sdk, setResources]
103
- )
104
-
105
- const removeResource = useCallback(
106
- (id: string) => sdk.resources.remove({ id })
107
- .then(() => setResources((resources = []) => removeBy('id', id, resources))),
108
- [sdk, setResources]
109
- )
110
-
111
- const updateResourceContent = useCallback(
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
- }),
117
- [sdk, workspaceId, setResources]
118
- )
119
-
120
- const moveResource = useCallback(
121
- // TODO: how should we add this to the new location in cache?
122
- // TODO: if recource is a direcotry, how should we move the nested resources from cache?
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
- }),
128
- [sdk, workspaceId, setResources]
129
- )
130
-
131
- const renameResource = useCallback(
132
- // TODO: how should we update the cache for individual resources
133
- // mabye by making this an internal function and only use it through useResource?
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
- }),
139
- [sdk, workspaceId, setResources]
140
- )
141
-
142
- useEffect(() => {
143
- if (!workspaceId) return
144
- if (!location) return
145
- if (status !== AsyncStatus.NotInitialized) return
146
-
147
- loadResources()
148
-
149
- }, [workspaceId, location, status])
150
-
151
- return {
152
- status,
153
- resources: locationSpecificResources,
154
- removeResource,
155
- createDocument,
156
- createDirectory,
157
- loadResource,
158
- updateResourceContent,
159
- moveResource,
160
- renameResource,
161
- uploadFile
162
- }
163
- }
package/src/useSdk.ts DELETED
@@ -1,7 +0,0 @@
1
- import { useContext } from 'react'
2
- import { Context } from './WorkspaceProvider'
3
-
4
- export function useSdk() {
5
- return useContext(Context).sdk
6
- }
7
-
package/src/useUser.ts DELETED
@@ -1,55 +0,0 @@
1
- import { useCallback, useEffect } from 'react'
2
- import { useCache } from './Cache'
3
- import { useSdk } from './useSdk'
4
- import { AsyncStatus } from './asyncStatus'
5
-
6
- const statusPath = ['user', 'status']
7
- const userPath = ['user', 'data']
8
-
9
- export const useUser = () => {
10
- const sdk = useSdk()
11
-
12
- const {
13
- data: status = AsyncStatus.NotInitialized,
14
- set: setStatus
15
- } = useCache(statusPath)
16
-
17
- const {
18
- data: user = {},
19
- set: setUser
20
- } = useCache(userPath)
21
-
22
- const update = useCallback(
23
- (user: any) => {
24
- return sdk.currentUser.update(user)
25
- .then((updatedUser: any) => {
26
- setUser(updatedUser)
27
- return updatedUser
28
- })
29
- },
30
- [sdk]
31
- )
32
-
33
- useEffect(() => {
34
- if (status !== AsyncStatus.NotInitialized) return
35
- setStatus(() => AsyncStatus.Loading)
36
-
37
- sdk.currentUser.get()
38
- .then((user: any) => {
39
- if (!user) return Promise.reject()
40
- setUser(user)
41
- setStatus(() => AsyncStatus.Success)
42
- })
43
- .catch(() => {
44
- setUser({})
45
- setStatus(() => AsyncStatus.Error)
46
- })
47
-
48
- }, [status, sdk])
49
-
50
- return {
51
- status,
52
- user,
53
- update
54
- }
55
- }
package/src/useUsers.ts DELETED
@@ -1,38 +0,0 @@
1
- import { useCallback, useEffect, useMemo } from 'react'
2
- import { useCache } from './Cache'
3
- import { AsyncStatus } from './asyncStatus'
4
- import { useSdk } from './useSdk'
5
-
6
- export const useUsers = () => {
7
- const sdk = useSdk()
8
- const workspaceId = sdk.workspaceId
9
- const cachePath = useMemo(() => ['workspace', workspaceId, 'users'], [workspaceId])
10
-
11
- const {
12
- data: users = { status: AsyncStatus.NotInitialized, data: [] },
13
- set: setUsers
14
- } = useCache(cachePath)
15
-
16
- const load = useCallback(() => {
17
- setUsers({ status: AsyncStatus.Loading, data: [] })
18
-
19
- sdk.users.list()
20
- .then((users: any[]) => setUsers({ data: users, status: AsyncStatus.Success }))
21
- .catch(() => setUsers({ status: AsyncStatus.Error, data: [] }))
22
-
23
- }, [sdk])
24
-
25
- useEffect(() => {
26
- if (!workspaceId) return
27
- if (users.status === AsyncStatus.NotInitialized) {
28
- load()
29
- }
30
- }, [workspaceId, users])
31
-
32
- return {
33
- status: users.status,
34
- users: users.data,
35
- load,
36
- }
37
-
38
- }
@@ -1,67 +0,0 @@
1
- import { useCallback, useEffect, useMemo } from 'react'
2
- import { useCache } from './Cache'
3
- import { AsyncStatus } from './asyncStatus'
4
- import { useSdk } from './useSdk'
5
-
6
- export const useWorkspace = () => {
7
- const sdk = useSdk()
8
- const workspaceId = sdk.workspaceId
9
- const cachePath = useMemo(() => ['workspace', workspaceId], [workspaceId])
10
-
11
- const {
12
- data: workspace = { status: AsyncStatus.NotInitialized, data: {} },
13
- set: setWorkspace
14
- } = useCache(cachePath)
15
-
16
- const loadWorkspace = useCallback(() => {
17
- setWorkspace({ status: AsyncStatus.Loading, data: {} })
18
- sdk.workspaces.current()
19
- .then((workspace: any) => setWorkspace({ data: workspace, status: AsyncStatus.Success }))
20
- .catch(() => setWorkspace({ status: AsyncStatus.Error, data: {} }))
21
- }, [sdk, workspaceId])
22
-
23
- const createApiToken = useCallback(
24
- (description: string) => sdk.workspaces.createApiToken({ description })
25
- .then(({ id, token }: { id: string, token: string }) => {
26
-
27
- setWorkspace({
28
- status: workspace.status,
29
- data: {
30
- ...workspace,
31
- apiTokens: [...workspace.apiTokens, { id, description }]
32
- }
33
- })
34
-
35
- return token
36
- }),
37
- [sdk]
38
- )
39
-
40
- const inviteUser = useCallback(
41
- (email: string) => sdk.workspaces.inviteUser({ email }),
42
- [sdk]
43
- )
44
-
45
- const enableService = () => {
46
-
47
- }
48
-
49
- const disabledService = () => {
50
-
51
- }
52
-
53
- useEffect(() => {
54
- if (!workspaceId) return
55
- if (workspace.status === AsyncStatus.NotInitialized) {
56
- loadWorkspace()
57
- }
58
- }, [workspaceId, workspace])
59
-
60
- return {
61
- status: workspace.status,
62
- workspace: workspace.data,
63
- loadWorkspace,
64
- createApiToken,
65
- inviteUser
66
- }
67
- }
@@ -1,49 +0,0 @@
1
- import { useCallback, useEffect } from 'react'
2
- import { useCache } from './Cache'
3
- import { AsyncStatus } from './asyncStatus'
4
- import { useSdk } from './useSdk'
5
-
6
- const cachePath = ['workspaces']
7
-
8
- export const useWorkspaces = () => {
9
- const sdk = useSdk()
10
-
11
- const {
12
- set: setWorkspaces,
13
- data: workspaces = { status: AsyncStatus.NotInitialized, data: [] }
14
- } = useCache(cachePath)
15
-
16
- const loadWorkspaces = useCallback(() => {
17
- setWorkspaces({ status: AsyncStatus.Loading, data: [] })
18
- sdk.workspaces.list()
19
- .then((workspaces: any[]) => setWorkspaces({ status: AsyncStatus.Success, data: workspaces }))
20
- .catch(() => setWorkspaces({ status: AsyncStatus.Error, data: [] }))
21
- }, [sdk])
22
-
23
- const createWorkspace = useCallback(
24
- (name: string) => sdk.workspaces.create({ name })
25
- .then((workspace: any) => {
26
-
27
- setWorkspaces({
28
- status: workspaces.status,
29
- data: [...workspaces.data, workspace]
30
- })
31
-
32
- return workspace
33
- }),
34
- [sdk]
35
- )
36
-
37
- useEffect(() => {
38
- if (workspaces.status === AsyncStatus.NotInitialized) {
39
- loadWorkspaces()
40
- }
41
- }, [workspaces, loadWorkspaces])
42
-
43
- return {
44
- status: workspaces.status,
45
- workspaces: workspaces.data,
46
- loadWorkspaces,
47
- createWorkspace
48
- }
49
- }
package/tsconfig.json DELETED
@@ -1,27 +0,0 @@
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
- }