@ossy/sdk 0.0.15 → 0.0.16
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 +8 -0
- package/package.json +2 -5
- package/src/Actions.ts +237 -0
- package/src/config.ts +5 -0
- package/src/sdk.ts +203 -0
- package/src/api-tokens-client.js +0 -23
- package/src/auth-client.js +0 -43
- package/src/http.js +0 -82
- package/src/resources-client.js +0 -108
- package/src/sdk.js +0 -46
- package/src/user-client.js +0 -32
- package/src/workspaces-client.js +0 -85
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.0.16 (2025-10-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ossy/sdk
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## 0.0.15 (2025-10-27)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @ossy/sdk
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/sdk",
|
|
3
3
|
"description": "Sofware Development Kit for interacting with our services",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.16",
|
|
5
5
|
"url": "git://github.com/ossy-se/packages/sdk",
|
|
6
6
|
"source": "src/public.index.ts",
|
|
7
7
|
"module": "build/public.index.js",
|
|
@@ -18,12 +18,9 @@
|
|
|
18
18
|
"build": "rollup -c rollup.config.js",
|
|
19
19
|
"test": ""
|
|
20
20
|
},
|
|
21
|
-
"dependencies": {
|
|
22
|
-
"ramda": "^0.32.0"
|
|
23
|
-
},
|
|
24
21
|
"publishConfig": {
|
|
25
22
|
"access": "public",
|
|
26
23
|
"registry": "https://registry.npmjs.org"
|
|
27
24
|
},
|
|
28
|
-
"gitHead": "
|
|
25
|
+
"gitHead": "6cf3fe944bcbd61a2deb8d2e24f982374415e6d4"
|
|
29
26
|
}
|
package/src/Actions.ts
ADDED
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
import { SDKConfig } from "./config";
|
|
2
|
+
|
|
3
|
+
export interface Action<Payload extends (Record<string, string | boolean | number> & SDKConfig) | undefined = {}> {
|
|
4
|
+
id: string;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
7
|
+
payload?: Payload
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const ApiTokenGetAll: Action = {
|
|
11
|
+
id: 'api-tokens.get-all',
|
|
12
|
+
endpoint: '/users/me/tokens',
|
|
13
|
+
method: 'GET'
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const ApiTokenCreate: Action<{
|
|
17
|
+
name: string,
|
|
18
|
+
description: string,
|
|
19
|
+
expiresAt: string;
|
|
20
|
+
}> = {
|
|
21
|
+
id: 'api-tokens.create',
|
|
22
|
+
endpoint: '/users/me/tokens',
|
|
23
|
+
method: 'POST'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const ApiTokenInvalidate: Action<{ id: string }> = {
|
|
27
|
+
id: 'api-tokens.invalidate',
|
|
28
|
+
endpoint: '/users/me/tokens/:id',
|
|
29
|
+
method: 'DELETE'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// WorkspacesClient actions
|
|
33
|
+
export const WorkspacesList: Action = {
|
|
34
|
+
id: 'workspaces.get-all',
|
|
35
|
+
endpoint: '/workspaces',
|
|
36
|
+
method: 'GET'
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const WorkspacesGet: Action<{ id: string }> = {
|
|
40
|
+
id: 'workspaces.by-id',
|
|
41
|
+
endpoint: '/workspaces/:id',
|
|
42
|
+
method: 'GET'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const WorkspacesCreate: Action<{ name: string }> = {
|
|
46
|
+
id: 'workspaces.create',
|
|
47
|
+
endpoint: '/workspaces',
|
|
48
|
+
method: 'POST'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export const WorkspacesImportResourceTemplates: Action<{ templates: any }> = {
|
|
52
|
+
id: 'workspaces.import-resource-templates',
|
|
53
|
+
endpoint: '/resource-templates',
|
|
54
|
+
method: 'POST'
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export const WorkspacesGetResourceTemplates: Action = {
|
|
58
|
+
id: 'workspaces.get-resource-templates',
|
|
59
|
+
endpoint: '/resource-templates',
|
|
60
|
+
method: 'GET'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const WorkspacesCreateApiToken: Action<{ description: string }> = {
|
|
64
|
+
id: 'workspaces.create-api-token',
|
|
65
|
+
endpoint: '/tokens',
|
|
66
|
+
method: 'POST'
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const WorkspacesGetApiTokens: Action = {
|
|
70
|
+
id: 'workspaces.get-api-tokens',
|
|
71
|
+
endpoint: '/tokens',
|
|
72
|
+
method: 'GET'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const WorkspacesInviteUser: Action<{ email: string }> = {
|
|
76
|
+
id: 'workspaces.invite-user',
|
|
77
|
+
endpoint: '/invitations',
|
|
78
|
+
method: 'POST'
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export const WorkspacesEnableService: Action<{ service: any }> = {
|
|
82
|
+
id: 'workspaces.enable-service',
|
|
83
|
+
endpoint: '/services/enable',
|
|
84
|
+
method: 'POST'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export const WorkspacesDisableService: Action<{ service: any }> = {
|
|
88
|
+
id: 'workspaces.disable-service',
|
|
89
|
+
endpoint: '/services/disable',
|
|
90
|
+
method: 'POST'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export const WorkspacesGetUsers: Action = {
|
|
94
|
+
id: 'workspaces.get-users',
|
|
95
|
+
endpoint: '/users',
|
|
96
|
+
method: 'GET'
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// UserClient actions
|
|
100
|
+
export const UserGet: Action = {
|
|
101
|
+
id: 'user.get',
|
|
102
|
+
endpoint: '/users/me',
|
|
103
|
+
method: 'GET'
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const UserGetHistory: Action = {
|
|
107
|
+
id: 'user.get-history',
|
|
108
|
+
endpoint: '/users/me/history',
|
|
109
|
+
method: 'GET'
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export const UserUpdate: Action<{ user: any }> = {
|
|
113
|
+
id: 'user.update',
|
|
114
|
+
endpoint: '/users/me',
|
|
115
|
+
method: 'PUT'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// ResourcesClient actions
|
|
119
|
+
export const ResourcesCreateDirectory: Action<{ type?: 'directory', location: string, name: string }> = {
|
|
120
|
+
id: 'resources.create-directory',
|
|
121
|
+
endpoint: '/resources',
|
|
122
|
+
method: 'POST',
|
|
123
|
+
//@ts-ignore
|
|
124
|
+
payload: {
|
|
125
|
+
type: 'directory'
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export const ResourcesCreate: Action<{ type: string, location: string, name: string, content?: any }> = {
|
|
130
|
+
id: 'resources.create',
|
|
131
|
+
endpoint: '/resources',
|
|
132
|
+
method: 'POST'
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export const ResourcesUpload: Action<{ location: string, type: string, name: string, size: number }> = {
|
|
136
|
+
id: 'resources.upload',
|
|
137
|
+
endpoint: '/resources',
|
|
138
|
+
method: 'POST'
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// This is for uploading different sizes of images etc.
|
|
142
|
+
export const ResourcesUploadNamedVersion: Action<{ id: string, name: string, size: number }> = {
|
|
143
|
+
id: 'resources.upload-named-version',
|
|
144
|
+
endpoint: '/resources/:id/:name',
|
|
145
|
+
method: 'PUT'
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export const ResourcesGet: Action<{ id: string }> = {
|
|
149
|
+
id: 'resources.get',
|
|
150
|
+
endpoint: '/resources/:id',
|
|
151
|
+
method: 'GET',
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export const ResourcesList: Action<{ search?: string }> = {
|
|
155
|
+
id: 'resources.list',
|
|
156
|
+
endpoint: '/resources?:search',
|
|
157
|
+
method: 'GET',
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const ResourcesSearch: Action<{ query: any }> = {
|
|
161
|
+
id: 'resources.search',
|
|
162
|
+
endpoint: '/resources/search',
|
|
163
|
+
method: 'POST'
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export const ResourcesRemove: Action<{ id: string }> = {
|
|
167
|
+
id: 'resources.remove',
|
|
168
|
+
endpoint: '/resources/:id',
|
|
169
|
+
method: 'DELETE'
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export const ResourcesUpdateContent: Action<{ id: string, content: any }> = {
|
|
173
|
+
id: 'resources.update-content',
|
|
174
|
+
endpoint: '/resources/:id/content',
|
|
175
|
+
method: 'PUT'
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export const ResourcesMove: Action<{ id: string, target: string }> = {
|
|
179
|
+
id: 'resources.move',
|
|
180
|
+
endpoint: '/resources/:id/location',
|
|
181
|
+
method: 'PUT'
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export const ResourcesRename: Action<{ id: string, name: string }> = {
|
|
185
|
+
id: 'resources.rename',
|
|
186
|
+
endpoint: '/resources/:id/name',
|
|
187
|
+
method: 'PUT'
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// AuthClient actions
|
|
191
|
+
export const AuthSignUp: Action<{ email: string }> = {
|
|
192
|
+
id: 'auth.sign-up',
|
|
193
|
+
endpoint: '/users/sign-up',
|
|
194
|
+
method: 'POST'
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export const AuthSignIn: Action<{ email: string }> = {
|
|
198
|
+
id: 'auth.sign-in',
|
|
199
|
+
endpoint: '/users/sign-in',
|
|
200
|
+
method: 'POST'
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export const AuthVerifySignIn: Action<{ token: string }> = {
|
|
204
|
+
id: 'auth.verify-sign-in',
|
|
205
|
+
endpoint: '/users/verify-sign-in?token=:token',
|
|
206
|
+
method: 'GET'
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export const AuthVerifyInvitation: Action<{ workspaceId: string, token: string }> = {
|
|
210
|
+
id: 'auth.verify-invitation',
|
|
211
|
+
endpoint: '/workspaces/:workspaceId/invitations?token=:token',
|
|
212
|
+
method: 'GET'
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export const AuthGetAuthenticatedUser: Action = {
|
|
216
|
+
id: 'auth.get-authenticated-user',
|
|
217
|
+
endpoint: '/users/me',
|
|
218
|
+
method: 'GET'
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
export const AuthGetAuthenticatedUserHistory: Action = {
|
|
222
|
+
id: 'auth.get-authenticated-user-history',
|
|
223
|
+
endpoint: '/users/me/history',
|
|
224
|
+
method: 'GET'
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export const AuthGetUser: Action<{ id: string }> = {
|
|
228
|
+
id: 'auth.get-user',
|
|
229
|
+
endpoint: '/users/:id',
|
|
230
|
+
method: 'GET'
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export const AuthSignOff: Action = {
|
|
234
|
+
id: 'auth.sign-off',
|
|
235
|
+
endpoint: '/users/sign-off',
|
|
236
|
+
method: 'GET'
|
|
237
|
+
}
|
package/src/config.ts
ADDED
package/src/sdk.ts
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Action,
|
|
3
|
+
ApiTokenCreate,
|
|
4
|
+
ApiTokenGetAll,
|
|
5
|
+
ApiTokenInvalidate,
|
|
6
|
+
WorkspacesList,
|
|
7
|
+
WorkspacesCreate,
|
|
8
|
+
WorkspacesImportResourceTemplates,
|
|
9
|
+
WorkspacesGetResourceTemplates,
|
|
10
|
+
WorkspacesCreateApiToken,
|
|
11
|
+
WorkspacesGetApiTokens,
|
|
12
|
+
WorkspacesInviteUser,
|
|
13
|
+
WorkspacesEnableService,
|
|
14
|
+
WorkspacesDisableService,
|
|
15
|
+
WorkspacesGetUsers,
|
|
16
|
+
UserGet,
|
|
17
|
+
UserGetHistory,
|
|
18
|
+
UserUpdate,
|
|
19
|
+
ResourcesCreateDirectory,
|
|
20
|
+
ResourcesCreate,
|
|
21
|
+
ResourcesUpload,
|
|
22
|
+
ResourcesUploadNamedVersion,
|
|
23
|
+
ResourcesGet,
|
|
24
|
+
ResourcesList,
|
|
25
|
+
ResourcesSearch,
|
|
26
|
+
ResourcesRemove,
|
|
27
|
+
ResourcesUpdateContent,
|
|
28
|
+
ResourcesMove,
|
|
29
|
+
ResourcesRename,
|
|
30
|
+
AuthSignUp,
|
|
31
|
+
AuthSignIn,
|
|
32
|
+
AuthVerifySignIn,
|
|
33
|
+
AuthVerifyInvitation,
|
|
34
|
+
AuthGetAuthenticatedUser,
|
|
35
|
+
AuthGetAuthenticatedUserHistory,
|
|
36
|
+
AuthGetUser,
|
|
37
|
+
AuthSignOff,
|
|
38
|
+
WorkspacesGet
|
|
39
|
+
} from './Actions';
|
|
40
|
+
import { SDKConfig } from './config'
|
|
41
|
+
|
|
42
|
+
export class SDK {
|
|
43
|
+
|
|
44
|
+
workspaceId?: string;
|
|
45
|
+
authorization?: string;
|
|
46
|
+
baseUrl = 'https://api.ossy.se/api/v0'
|
|
47
|
+
|
|
48
|
+
static of(config: SDKConfig) {
|
|
49
|
+
return new SDK(config)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
constructor(config: SDKConfig) {
|
|
53
|
+
this.updateConfig(config)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
updateConfig(intendedConfig: SDKConfig) {
|
|
57
|
+
this.baseUrl = intendedConfig.apiUrl || this.baseUrl
|
|
58
|
+
this.workspaceId = intendedConfig.workspaceId || this.workspaceId
|
|
59
|
+
this.authorization = intendedConfig.authorization || this.authorization
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
get apiTokens() {
|
|
63
|
+
return {
|
|
64
|
+
list: this.makeRequest(ApiTokenGetAll).bind(this),
|
|
65
|
+
create: this.makeRequest(ApiTokenCreate).bind(this),
|
|
66
|
+
invalidate: this.makeRequest(ApiTokenInvalidate).bind(this)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get workspaces() {
|
|
71
|
+
return {
|
|
72
|
+
list: this.makeRequest(WorkspacesList).bind(this),
|
|
73
|
+
get: this.makeRequest(WorkspacesGet).bind(this),
|
|
74
|
+
create: this.makeRequest(WorkspacesCreate).bind(this),
|
|
75
|
+
importResourceTemplates: this.makeRequest(WorkspacesImportResourceTemplates).bind(this),
|
|
76
|
+
getResourceTemplates: this.makeRequest(WorkspacesGetResourceTemplates).bind(this),
|
|
77
|
+
createApiToken: this.makeRequest(WorkspacesCreateApiToken).bind(this),
|
|
78
|
+
getApiTokens: this.makeRequest(WorkspacesGetApiTokens).bind(this),
|
|
79
|
+
inviteUser: this.makeRequest(WorkspacesInviteUser).bind(this),
|
|
80
|
+
enableService: this.makeRequest(WorkspacesEnableService).bind(this),
|
|
81
|
+
disableService: this.makeRequest(WorkspacesDisableService).bind(this),
|
|
82
|
+
getUsers: this.makeRequest(WorkspacesGetUsers).bind(this),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get user() {
|
|
87
|
+
return {
|
|
88
|
+
get: this.makeRequest(UserGet).bind(this),
|
|
89
|
+
getHistory: this.makeRequest(UserGetHistory).bind(this),
|
|
90
|
+
update: this.makeRequest(UserUpdate).bind(this),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get resources() {
|
|
95
|
+
return {
|
|
96
|
+
createDirectory: this.makeRequest(ResourcesCreateDirectory).bind(this),
|
|
97
|
+
create: this.makeRequest(ResourcesCreate).bind(this),
|
|
98
|
+
upload: ({ location = '/', file }: { location: string; file: File} ) => {
|
|
99
|
+
const payload = {
|
|
100
|
+
type: file.type,
|
|
101
|
+
location: location,
|
|
102
|
+
name: file.name,
|
|
103
|
+
size: file.size
|
|
104
|
+
}
|
|
105
|
+
return this.makeRequest(ResourcesUpload)(payload)
|
|
106
|
+
.then(resource => {
|
|
107
|
+
return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
|
|
108
|
+
.then(() => resource)
|
|
109
|
+
})
|
|
110
|
+
},
|
|
111
|
+
uploadNamedVersion: ({ id, name, file }: { id: string, name: string, file: File }) => {
|
|
112
|
+
const payload = {
|
|
113
|
+
id: id,
|
|
114
|
+
name: name,
|
|
115
|
+
size: file.size
|
|
116
|
+
}
|
|
117
|
+
this.makeRequest(ResourcesUploadNamedVersion)(payload)
|
|
118
|
+
.then(resource => {
|
|
119
|
+
return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
|
|
120
|
+
.then(() => resource)
|
|
121
|
+
})
|
|
122
|
+
},
|
|
123
|
+
get: this.makeRequest(ResourcesGet).bind(this),
|
|
124
|
+
list: (query: (Record<string, string> & { location?: string })) => {
|
|
125
|
+
const search = new URLSearchParams({ ...query }).toString()
|
|
126
|
+
return this.makeRequest(ResourcesList)({ search })
|
|
127
|
+
},
|
|
128
|
+
search: this.makeRequest(ResourcesSearch).bind(this),
|
|
129
|
+
remove: this.makeRequest(ResourcesRemove).bind(this),
|
|
130
|
+
updateContent: this.makeRequest(ResourcesUpdateContent).bind(this),
|
|
131
|
+
move: this.makeRequest(ResourcesMove).bind(this),
|
|
132
|
+
rename: this.makeRequest(ResourcesRename).bind(this),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
get auth() {
|
|
137
|
+
return {
|
|
138
|
+
signUp: this.makeRequest(AuthSignUp).bind(this),
|
|
139
|
+
signIn: this.makeRequest(AuthSignIn).bind(this),
|
|
140
|
+
verifySignIn: this.makeRequest(AuthVerifySignIn).bind(this),
|
|
141
|
+
verifyInvitation: this.makeRequest(AuthVerifyInvitation).bind(this),
|
|
142
|
+
getAuthenticatedUser: this.makeRequest(AuthGetAuthenticatedUser).bind(this),
|
|
143
|
+
getAuthenticatedUserHistory: this.makeRequest(AuthGetAuthenticatedUserHistory).bind(this),
|
|
144
|
+
getUser: this.makeRequest(AuthGetUser).bind(this),
|
|
145
|
+
signOff: this.makeRequest(AuthSignOff).bind(this),
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
makeRequest = <T extends Action>(action: T) => {
|
|
150
|
+
return (_payload: Required<T['payload']>) => {
|
|
151
|
+
|
|
152
|
+
let payload: Required<T['payload']> = {} as Required<T['payload']>;
|
|
153
|
+
|
|
154
|
+
if (!!_payload || action.payload) {
|
|
155
|
+
payload = {
|
|
156
|
+
...(action.payload || {}),
|
|
157
|
+
...(_payload || {})
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
let baseUrl: string = 'apiUrl' in payload ? payload?.apiUrl as string : this.baseUrl
|
|
162
|
+
let workspaceId = 'workspaceId' in payload ? payload.workspaceId : this.workspaceId;
|
|
163
|
+
let authorization = 'authorization' in payload ? payload.authorization : this.authorization;
|
|
164
|
+
let body: string | undefined = undefined;
|
|
165
|
+
let endpoint = action.endpoint;
|
|
166
|
+
|
|
167
|
+
if (payload) {
|
|
168
|
+
body = JSON.stringify(payload);
|
|
169
|
+
|
|
170
|
+
const paramNames = (action.endpoint.match(/:([a-zA-Z0-9_]+)/g) || []).map(
|
|
171
|
+
param => param.slice(1) as keyof T['payload']
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
endpoint = paramNames.reduce(
|
|
175
|
+
(endpoint, paramName) => endpoint.replace(String(paramName), String(payload[paramName])),
|
|
176
|
+
action.endpoint
|
|
177
|
+
)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
return fetch(`${baseUrl}${endpoint}`, {
|
|
181
|
+
credentials: 'include',
|
|
182
|
+
headers: {
|
|
183
|
+
'Content-Type': 'application/json',
|
|
184
|
+
workspaceId: workspaceId as string,
|
|
185
|
+
Authorization: authorization as string
|
|
186
|
+
|
|
187
|
+
},
|
|
188
|
+
method: action.method,
|
|
189
|
+
body
|
|
190
|
+
}).then(response => {
|
|
191
|
+
const contentType = response.headers.get('Content-Type') || ''
|
|
192
|
+
const status = response.status
|
|
193
|
+
const okResponseCodes = [200, 204]
|
|
194
|
+
if (status === 400) return response.json().then(content => Promise.reject(content.error))
|
|
195
|
+
if (!okResponseCodes.includes(status)) return Promise.reject(response)
|
|
196
|
+
if (contentType.includes('application/json')) return response.json()
|
|
197
|
+
return response
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
package/src/api-tokens-client.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export class ApiTokensClient {
|
|
2
|
-
|
|
3
|
-
static of(config) {
|
|
4
|
-
return new ApiTokensClient(config)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.http = config?.http
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
create({ name, description, expiresAt }) {
|
|
12
|
-
return this.http.post('/users/me/tokens', { name, description, expiresAt })
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getAll() {
|
|
16
|
-
return this.http.get('/users/me/tokens')
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
invalidate(tokenId) {
|
|
20
|
-
return this.http.delete(`/users/me/tokens/${tokenId}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
}
|
package/src/auth-client.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
export class AuthClient {
|
|
2
|
-
|
|
3
|
-
static of(config) {
|
|
4
|
-
return new AuthClient(config)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.http = config?.http
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
signUp(email) {
|
|
12
|
-
return this.http.post('/users/sign-up', email)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
signIn(email) {
|
|
16
|
-
return this.http.post('/users/sign-in', email)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
verifySignIn(token) {
|
|
20
|
-
return this.http.get(`/users/verify-sign-in?token=${token}`)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
verifyInvitation(workspaceId, token) {
|
|
24
|
-
return this.http.get(`/workspaces/${workspaceId}/invitations?token=${token}`)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getAuthenticatedUser() {
|
|
28
|
-
return this.http.get(`/users/me`)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getAuthenticatedUserHistory() {
|
|
32
|
-
return this.http.get(`/users/me/history`)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
getUser(userId) {
|
|
36
|
-
return this.http.get(`/users/${userId}`)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
signOff() {
|
|
40
|
-
return this.http.get('/users/sign-off')
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
package/src/http.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { mergeRight } from 'ramda'
|
|
2
|
-
|
|
3
|
-
const defaultHeaders = {
|
|
4
|
-
'Content-Type': 'application/json',
|
|
5
|
-
'Accept': 'application/json'
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class Http {
|
|
9
|
-
|
|
10
|
-
static of(config) {
|
|
11
|
-
return new Http(config)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
constructor(config) {
|
|
16
|
-
this.baseUrl = config.baseUrl
|
|
17
|
-
|
|
18
|
-
if (typeof config?.headers === 'object') {
|
|
19
|
-
this.getHeaders = () => Promise.resolve({
|
|
20
|
-
...defaultHeaders,
|
|
21
|
-
...config.headers
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (typeof config?.headers === 'function') {
|
|
26
|
-
this.getHeaders = config.headers
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
post(endpoint, body) {
|
|
31
|
-
|
|
32
|
-
const config = {
|
|
33
|
-
method: 'POST',
|
|
34
|
-
body: JSON.stringify(body)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return this.fetch(endpoint, config)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
get(endpoint) {
|
|
41
|
-
const config = { method: 'GET' }
|
|
42
|
-
return this.fetch(endpoint, config)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
delete(endpoint) {
|
|
46
|
-
const config = { method: 'DELETE' }
|
|
47
|
-
return this.fetch(endpoint, config)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
put(endpoint, body) {
|
|
51
|
-
|
|
52
|
-
const config = {
|
|
53
|
-
method: 'PUT',
|
|
54
|
-
body: JSON.stringify(body)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return this.fetch(endpoint, config)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
async fetch(endpoint, config) {
|
|
61
|
-
const headers = await this.getHeaders()
|
|
62
|
-
|
|
63
|
-
const defaultConfig = {
|
|
64
|
-
headers: headers,
|
|
65
|
-
credentials: 'include'
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return fetch(
|
|
69
|
-
`${this.baseUrl}${endpoint}`,
|
|
70
|
-
mergeRight(config, defaultConfig)
|
|
71
|
-
).then(response => {
|
|
72
|
-
const contentType = response.headers.get('Content-Type') || ''
|
|
73
|
-
const status = response.status
|
|
74
|
-
const okResponseCodes = [200, 204]
|
|
75
|
-
if (status === 400) return response.json().then(content => Promise.reject(content.error))
|
|
76
|
-
if (!okResponseCodes.includes(status)) return Promise.reject(response)
|
|
77
|
-
if (contentType.includes('application/json')) return response.json()
|
|
78
|
-
return response
|
|
79
|
-
})
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
}
|
package/src/resources-client.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
export class ResourcesClient {
|
|
2
|
-
|
|
3
|
-
static of(config) {
|
|
4
|
-
return new ResourcesClient(config)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.http = config?.http
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
createDirectory({ location, name }) {
|
|
12
|
-
return this.http.post(`/resources`, {
|
|
13
|
-
type: 'directory',
|
|
14
|
-
location: location,
|
|
15
|
-
name: name
|
|
16
|
-
})
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
//** Deprecated **//
|
|
20
|
-
createDocument(document) {
|
|
21
|
-
return this.create(document);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
create(document) {
|
|
25
|
-
return this.http.post(`/resources`, {
|
|
26
|
-
type: document.type,
|
|
27
|
-
location: document.location,
|
|
28
|
-
name: document.name,
|
|
29
|
-
content: document.content
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
upload({ location = '/', file }) {
|
|
34
|
-
return this.http.post(`/resources`, {
|
|
35
|
-
type: file.type,
|
|
36
|
-
location: location,
|
|
37
|
-
name: file.name,
|
|
38
|
-
size: file.size
|
|
39
|
-
})
|
|
40
|
-
.then(resource => {
|
|
41
|
-
return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
|
|
42
|
-
.then(() => resource)
|
|
43
|
-
})
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// This is for uploading different sizes of images
|
|
47
|
-
uploadNamedVersion({ resourceId, name, file }) {
|
|
48
|
-
return this.http.put(`/resources/${resourceId}/${name}`, {
|
|
49
|
-
type: file.type,
|
|
50
|
-
size: file.size
|
|
51
|
-
})
|
|
52
|
-
.then(resource => {
|
|
53
|
-
return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
|
|
54
|
-
.then(() => resource)
|
|
55
|
-
})
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
byId(resourceId) {
|
|
59
|
-
return this.http.get(`/resources/${resourceId}`)
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
byLocation(location = '/') {
|
|
63
|
-
return this.http.get(`/resources?location=${location}`)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
get(query = {}) {
|
|
67
|
-
|
|
68
|
-
if (typeof query === 'string') {
|
|
69
|
-
return this.byId(query)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const search = new URLSearchParams(query).toString()
|
|
73
|
-
return this.http.get(`/resources?${search}`)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// for complex queries where not all parameters can be serialized in the URL
|
|
77
|
-
search(query = {}) {
|
|
78
|
-
|
|
79
|
-
if (typeof query === 'string') {
|
|
80
|
-
return this.byId(query)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return this.http.post(`/resources/search`, query)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
remove(resourceId) {
|
|
87
|
-
return this.http.delete(`/resources/${resourceId}`)
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
updateContent(resourceId, resourceContent) {
|
|
91
|
-
return this.http.put(`/resources/${resourceId}/content`, resourceContent)
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
move(resourceId, newLocation) {
|
|
95
|
-
return this.http.put(
|
|
96
|
-
`/resources/${resourceId}/location`,
|
|
97
|
-
newLocation
|
|
98
|
-
)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
rename(resourceId, newName) {
|
|
102
|
-
return this.http.put(
|
|
103
|
-
`/resources/${resourceId}/name`,
|
|
104
|
-
newName
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
}
|
package/src/sdk.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { AuthClient } from './auth-client.js'
|
|
2
|
-
import { JobsClient } from './jobs-client.js'
|
|
3
|
-
import { ApiTokensClient } from './api-tokens-client.js'
|
|
4
|
-
import { ResourcesClient } from './resources-client.js'
|
|
5
|
-
import { UserClient } from './user-client.js'
|
|
6
|
-
import { WorkspacesClient } from './workspaces-client.js'
|
|
7
|
-
import { Http } from './http.js'
|
|
8
|
-
|
|
9
|
-
export class SDK {
|
|
10
|
-
|
|
11
|
-
static of(config) {
|
|
12
|
-
return new SDK(config)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
constructor(config) {
|
|
16
|
-
this.updateConfig(config)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
updateConfig(intendedConfig) {
|
|
20
|
-
const oldConfig = this.config || {}
|
|
21
|
-
|
|
22
|
-
this.config = {
|
|
23
|
-
...oldConfig,
|
|
24
|
-
...intendedConfig
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const http = Http.of({
|
|
28
|
-
baseUrl: this.config?.apiUrl || 'https://api.ossy.se/api/v0',
|
|
29
|
-
headers: {
|
|
30
|
-
workspaceId: this.config?.workspaceId,
|
|
31
|
-
Authorization: this.config?.apiKey
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
this.workspaceId = this.config.workspaceId
|
|
36
|
-
this.user = UserClient.of({ ...this.config, http })
|
|
37
|
-
this.auth = AuthClient.of({ ...this.config, http })
|
|
38
|
-
this.workspaces = WorkspacesClient.of({ ...this.config, http })
|
|
39
|
-
this.apiTokens = ApiTokensClient.of({ ...this.config, http })
|
|
40
|
-
this.resources = ResourcesClient.of({ ...this.config, http })
|
|
41
|
-
this.jobs = JobsClient.of({ ...this.config, http, resources: this.resources })
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
package/src/user-client.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
export class UserClient {
|
|
2
|
-
|
|
3
|
-
static of(config) {
|
|
4
|
-
return new UserClient(config)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.http = config?.http
|
|
9
|
-
|
|
10
|
-
this.services = {
|
|
11
|
-
enable: x => this.enableService(x),
|
|
12
|
-
disable: x => this.disableService(x)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
this.details = () => this.getUser()
|
|
16
|
-
this.history = () => this.getHistory()
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getUser() {
|
|
21
|
-
return this.http.get('/users/me')
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getHistory() {
|
|
25
|
-
return this.http.get('/users/me/history')
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
update(user) {
|
|
29
|
-
return this.http.put('/users/me', user)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
package/src/workspaces-client.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
export class WorkspacesClient {
|
|
2
|
-
|
|
3
|
-
static of(config) {
|
|
4
|
-
return new WorkspacesClient(config)
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
constructor(config) {
|
|
8
|
-
this.workspaceId = config?.workspaceId
|
|
9
|
-
this.http = config?.http
|
|
10
|
-
|
|
11
|
-
this.services = {
|
|
12
|
-
enable: x => this.enableService(x),
|
|
13
|
-
disable: x => this.disableService(x)
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
this.users = () => this.getUsers()
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getAll() {
|
|
21
|
-
return this.http.get('/workspaces')
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
byId(workspaceId) {
|
|
25
|
-
return this.http.get(`/workspaces/${workspaceId}`)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
create(workspaceName) {
|
|
29
|
-
return this.http.post('/workspaces', workspaceName)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
importResourceTempaltes(workspaceId, templates) {
|
|
33
|
-
return this.http.post(
|
|
34
|
-
`/resource-templates`,
|
|
35
|
-
templates
|
|
36
|
-
)
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getResourceTemplates(workspaceId) {
|
|
40
|
-
return this.http.get(
|
|
41
|
-
`/resource-templates`
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
createApiToken(workspaceId, description) {
|
|
46
|
-
return this.http.post(
|
|
47
|
-
`/tokens`,
|
|
48
|
-
{ workspaceId, description }
|
|
49
|
-
)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
getApiTokens(workspaceId) {
|
|
53
|
-
return this.http.get(
|
|
54
|
-
`/tokens`
|
|
55
|
-
)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
inviteUser(workspaceId, email) {
|
|
59
|
-
return this.http.post(
|
|
60
|
-
`/invitations`,
|
|
61
|
-
email
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
enableService(service) {
|
|
66
|
-
return this.http.post(
|
|
67
|
-
`/services/enable`,
|
|
68
|
-
service
|
|
69
|
-
)
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
disableService(service) {
|
|
73
|
-
return this.http.post(
|
|
74
|
-
`/services/disable`,
|
|
75
|
-
service
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
getUsers() {
|
|
80
|
-
return this.http.get(
|
|
81
|
-
`/users`
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
}
|