@ossy/sdk 0.0.16-alpha → 0.1.0

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 ADDED
@@ -0,0 +1,131 @@
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.1.0 (2025-10-30)
7
+
8
+
9
+ ### Features
10
+
11
+ * **sdk:** get current workspace ([#4](https://github.com/ossy-se/packages/issues/4)) ([afce7d5](https://github.com/ossy-se/packages/commit/afce7d5787af42691f62c9eba672ea1be000e19e))
12
+
13
+
14
+
15
+
16
+
17
+ ## 0.0.16 (2025-10-30)
18
+
19
+ **Note:** Version bump only for package @ossy/sdk
20
+
21
+
22
+
23
+
24
+
25
+ ## 0.0.15 (2025-10-27)
26
+
27
+ **Note:** Version bump only for package @ossy/sdk
28
+
29
+
30
+
31
+
32
+
33
+ ## 0.0.14 (2025-10-27)
34
+
35
+ **Note:** Version bump only for package @ossy/sdk
36
+
37
+
38
+
39
+
40
+
41
+ ## 0.0.13 (2025-10-27)
42
+
43
+ **Note:** Version bump only for package @ossy/sdk
44
+
45
+
46
+
47
+
48
+
49
+ ## 0.0.12 (2025-10-27)
50
+
51
+ **Note:** Version bump only for package @ossy/sdk
52
+
53
+
54
+
55
+
56
+
57
+ ## 0.0.11 (2025-10-27)
58
+
59
+ **Note:** Version bump only for package @ossy/sdk
60
+
61
+
62
+
63
+
64
+
65
+ ## 0.0.10 (2025-10-25)
66
+
67
+ **Note:** Version bump only for package @ossy/sdk
68
+
69
+
70
+
71
+
72
+
73
+ ## 0.0.9 (2025-10-25)
74
+
75
+ **Note:** Version bump only for package @ossy/sdk
76
+
77
+
78
+
79
+
80
+
81
+ ## 0.0.8 (2025-10-25)
82
+
83
+ **Note:** Version bump only for package @ossy/sdk
84
+
85
+
86
+
87
+
88
+
89
+ ## 0.0.7 (2025-10-25)
90
+
91
+ **Note:** Version bump only for package @ossy/sdk
92
+
93
+
94
+
95
+
96
+
97
+ ## 0.0.6 (2025-10-25)
98
+
99
+ **Note:** Version bump only for package @ossy/sdk
100
+
101
+
102
+
103
+
104
+
105
+ ## 0.0.5 (2025-10-25)
106
+
107
+ **Note:** Version bump only for package @ossy/sdk
108
+
109
+
110
+
111
+
112
+
113
+ ## 0.0.4 (2025-10-25)
114
+
115
+ **Note:** Version bump only for package @ossy/sdk
116
+
117
+
118
+
119
+
120
+
121
+ ## 0.0.3 (2025-10-25)
122
+
123
+ **Note:** Version bump only for package @ossy/sdk
124
+
125
+
126
+
127
+
128
+
129
+ ## 0.0.2 (2025-10-25)
130
+
131
+ **Note:** Version bump only for package @ossy/sdk
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/package.json CHANGED
@@ -1,30 +1,26 @@
1
1
  {
2
2
  "name": "@ossy/sdk",
3
- "description": "Sofware Development Kit for interactive with our services",
4
- "version": "0.0.16-alpha",
5
- "url": "git://github.com/ossy-se/ossy.git",
6
- "source": "src/index.js",
7
- "main": "build/index.cjs.js",
8
- "module": "build/index.esm.js",
3
+ "description": "Sofware Development Kit for interacting with our services",
4
+ "version": "0.1.0",
5
+ "url": "git://github.com/ossy-se/packages/sdk",
6
+ "source": "src/public.index.ts",
7
+ "module": "build/public.index.js",
8
+ "types": "build/public.index.d.ts",
9
+ "type": "module",
9
10
  "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://github.com/ossy-se/packages.git"
14
+ },
15
+ "license": "MIT",
10
16
  "scripts": {
11
17
  "start": "",
12
- "build": "rm -rf && rollup -c rollup.config.js",
18
+ "build": "rollup -c rollup.config.js",
13
19
  "test": ""
14
20
  },
15
- "dependencies": {
16
- "ramda": "^0.27.1"
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "registry": "https://registry.npmjs.org"
17
24
  },
18
- "devDependencies": {
19
- "@babel/core": "^7.14.5",
20
- "@babel/eslint-parser": "^7.15.8",
21
- "@babel/preset-react": "^7.14.5",
22
- "@rollup/plugin-commonjs": "^21.0.1",
23
- "@rollup/plugin-node-resolve": "^13.0.0",
24
- "babel-loader": "^8.2.2",
25
- "rollup": "^2.37.1",
26
- "rollup-plugin-babel": "^4.4.0",
27
- "rollup-plugin-peer-deps-external": "^2.2.4",
28
- "rollup-plugin-terser": "^7.0.2"
29
- }
25
+ "gitHead": "286499c80fddc83845d05f46cb4f60fb7c17a7d3"
30
26
  }
package/rollup.config.js CHANGED
@@ -1,30 +1,38 @@
1
- import babel from 'rollup-plugin-babel'
2
- import { nodeResolve } from '@rollup/plugin-node-resolve'
1
+ import typescript from '@rollup/plugin-typescript'
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
- import { terser as minifyJS } from 'rollup-plugin-terser'
6
- import pkg from './package.json'
5
+ import minifyJS from '@rollup/plugin-terser'
6
+ import pkg from './package.json' with { type: 'json' };
7
+ import { dts } from "rollup-plugin-dts"
7
8
 
8
- export default {
9
- input: pkg.source,
10
- output: [
11
- {
12
- file: pkg.main,
13
- format: 'cjs'
14
- },
15
- {
16
- file: pkg.module,
17
- format: 'esm'
18
- }
19
- ],
20
- plugins: [
21
- nodeResolve(),
22
- commonjs(),
23
- babel({
24
- exclude: ['**/node_modules/**/*'],
25
- presets: ['@babel/preset-react']
26
- }),
27
- removeOwnPeerDependencies(),
28
- minifyJS()
29
- ]
30
- }
9
+ export default [
10
+ {
11
+ input: pkg.source,
12
+ output: [
13
+ {
14
+ dir: 'build',
15
+ preserveModules: true,
16
+ format: 'esm'
17
+ }
18
+ ],
19
+ plugins: [
20
+ resolveCommonJsDependencies(),
21
+ resolveDependencies(),
22
+ resolveCommonJsDependencies(),
23
+ typescript({
24
+ tsconfig: "./tsconfig.json",
25
+ outDir: 'build',
26
+ }),
27
+ removeOwnPeerDependencies(),
28
+ minifyJS()
29
+ ]
30
+ },
31
+ {
32
+ input: "build/types/public.index.d.ts",
33
+ output: [{ file: "build/public.index.d.ts", format: "es" }],
34
+ plugins: [
35
+ dts()
36
+ ],
37
+ },
38
+ ]
package/src/Actions.ts ADDED
@@ -0,0 +1,243 @@
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 WorkspacesGetCurrent: Action = {
40
+ id: 'workspaces.get-current',
41
+ endpoint: '/workspaces/current',
42
+ method: 'GET'
43
+ }
44
+
45
+ export const WorkspacesGet: Action<{ id: string }> = {
46
+ id: 'workspaces.get',
47
+ endpoint: '/workspaces/:id',
48
+ method: 'GET'
49
+ }
50
+
51
+ export const WorkspacesCreate: Action<{ name: string }> = {
52
+ id: 'workspaces.create',
53
+ endpoint: '/workspaces',
54
+ method: 'POST'
55
+ }
56
+
57
+ export const WorkspacesImportResourceTemplates: Action<{ templates: any }> = {
58
+ id: 'workspaces.import-resource-templates',
59
+ endpoint: '/resource-templates',
60
+ method: 'POST'
61
+ }
62
+
63
+ export const WorkspacesGetResourceTemplates: Action = {
64
+ id: 'workspaces.get-resource-templates',
65
+ endpoint: '/resource-templates',
66
+ method: 'GET'
67
+ }
68
+
69
+ export const WorkspacesCreateApiToken: Action<{ description: string }> = {
70
+ id: 'workspaces.create-api-token',
71
+ endpoint: '/tokens',
72
+ method: 'POST'
73
+ }
74
+
75
+ export const WorkspacesGetApiTokens: Action = {
76
+ id: 'workspaces.get-api-tokens',
77
+ endpoint: '/tokens',
78
+ method: 'GET'
79
+ }
80
+
81
+ export const WorkspacesInviteUser: Action<{ email: string }> = {
82
+ id: 'workspaces.invite-user',
83
+ endpoint: '/invitations',
84
+ method: 'POST'
85
+ }
86
+
87
+ export const WorkspacesEnableService: Action<{ service: any }> = {
88
+ id: 'workspaces.enable-service',
89
+ endpoint: '/services/enable',
90
+ method: 'POST'
91
+ }
92
+
93
+ export const WorkspacesDisableService: Action<{ service: any }> = {
94
+ id: 'workspaces.disable-service',
95
+ endpoint: '/services/disable',
96
+ method: 'POST'
97
+ }
98
+
99
+ export const WorkspacesGetUsers: Action = {
100
+ id: 'workspaces.get-users',
101
+ endpoint: '/users',
102
+ method: 'GET'
103
+ }
104
+
105
+ // UserClient actions
106
+ export const UserCurrentGet: Action = {
107
+ id: 'user.get',
108
+ endpoint: '/users/me',
109
+ method: 'GET'
110
+ }
111
+
112
+ export const UserCurrentGetHistory: Action = {
113
+ id: 'user.get-history',
114
+ endpoint: '/users/me/history',
115
+ method: 'GET'
116
+ }
117
+
118
+ export const UserCurrentUpdate: Action<{ user: any }> = {
119
+ id: 'user.update',
120
+ endpoint: '/users/me',
121
+ method: 'PUT'
122
+ }
123
+
124
+ // ResourcesClient actions
125
+ export const ResourcesCreateDirectory: Action<{ type?: 'directory', location: string, name: string }> = {
126
+ id: 'resources.create-directory',
127
+ endpoint: '/resources',
128
+ method: 'POST',
129
+ //@ts-ignore
130
+ payload: {
131
+ type: 'directory'
132
+ }
133
+ }
134
+
135
+ export const ResourcesCreate: Action<{ type: string, location: string, name: string, content?: any }> = {
136
+ id: 'resources.create',
137
+ endpoint: '/resources',
138
+ method: 'POST'
139
+ }
140
+
141
+ export const ResourcesUpload: Action<{ location: string, type: string, name: string, size: number }> = {
142
+ id: 'resources.upload',
143
+ endpoint: '/resources',
144
+ method: 'POST'
145
+ }
146
+
147
+ // This is for uploading different sizes of images etc.
148
+ export const ResourcesUploadNamedVersion: Action<{ id: string, name: string, size: number }> = {
149
+ id: 'resources.upload-named-version',
150
+ endpoint: '/resources/:id/:name',
151
+ method: 'PUT'
152
+ }
153
+
154
+ export const ResourcesGet: Action<{ id: string }> = {
155
+ id: 'resources.get',
156
+ endpoint: '/resources/:id',
157
+ method: 'GET',
158
+ }
159
+
160
+ export const ResourcesList: Action<{ search?: string }> = {
161
+ id: 'resources.list',
162
+ endpoint: '/resources?:search',
163
+ method: 'GET',
164
+ }
165
+
166
+ export const ResourcesSearch: Action<{ query: any }> = {
167
+ id: 'resources.search',
168
+ endpoint: '/resources/search',
169
+ method: 'POST'
170
+ }
171
+
172
+ export const ResourcesRemove: Action<{ id: string }> = {
173
+ id: 'resources.remove',
174
+ endpoint: '/resources/:id',
175
+ method: 'DELETE'
176
+ }
177
+
178
+ export const ResourcesUpdateContent: Action<{ id: string, content: any }> = {
179
+ id: 'resources.update-content',
180
+ endpoint: '/resources/:id/content',
181
+ method: 'PUT'
182
+ }
183
+
184
+ export const ResourcesMove: Action<{ id: string, target: string }> = {
185
+ id: 'resources.move',
186
+ endpoint: '/resources/:id/location',
187
+ method: 'PUT'
188
+ }
189
+
190
+ export const ResourcesRename: Action<{ id: string, name: string }> = {
191
+ id: 'resources.rename',
192
+ endpoint: '/resources/:id/name',
193
+ method: 'PUT'
194
+ }
195
+
196
+ // AuthClient actions
197
+ export const AuthSignUp: Action<{ email: string }> = {
198
+ id: 'auth.sign-up',
199
+ endpoint: '/users/sign-up',
200
+ method: 'POST'
201
+ }
202
+
203
+ export const AuthSignIn: Action<{ email: string }> = {
204
+ id: 'auth.sign-in',
205
+ endpoint: '/users/sign-in',
206
+ method: 'POST'
207
+ }
208
+
209
+ export const AuthVerifySignIn: Action<{ token: string }> = {
210
+ id: 'auth.verify-sign-in',
211
+ endpoint: '/users/verify-sign-in?token=:token',
212
+ method: 'GET'
213
+ }
214
+
215
+ export const AuthVerifyInvitation: Action<{ workspaceId: string, token: string }> = {
216
+ id: 'auth.verify-invitation',
217
+ endpoint: '/workspaces/:workspaceId/invitations?token=:token',
218
+ method: 'GET'
219
+ }
220
+
221
+ export const AuthGetAuthenticatedUser: Action = {
222
+ id: 'auth.get-authenticated-user',
223
+ endpoint: '/users/me',
224
+ method: 'GET'
225
+ }
226
+
227
+ export const AuthGetAuthenticatedUserHistory: Action = {
228
+ id: 'auth.get-authenticated-user-history',
229
+ endpoint: '/users/me/history',
230
+ method: 'GET'
231
+ }
232
+
233
+ export const AuthGetUser: Action<{ id: string }> = {
234
+ id: 'auth.get-user',
235
+ endpoint: '/users/:id',
236
+ method: 'GET'
237
+ }
238
+
239
+ export const AuthSignOff: Action = {
240
+ id: 'auth.sign-off',
241
+ endpoint: '/users/sign-off',
242
+ method: 'GET'
243
+ }
package/src/config.ts ADDED
@@ -0,0 +1,5 @@
1
+ export interface SDKConfig {
2
+ apiUrl?: string;
3
+ workspaceId?: string;
4
+ authorization?: string
5
+ }
@@ -0,0 +1,2 @@
1
+ export * from './sdk.js'
2
+ export { Jobs, JobStatus } from './jobs-client.js'
package/src/sdk.ts ADDED
@@ -0,0 +1,210 @@
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
+ ResourcesCreateDirectory,
17
+ ResourcesCreate,
18
+ ResourcesUpload,
19
+ ResourcesUploadNamedVersion,
20
+ ResourcesGet,
21
+ ResourcesList,
22
+ ResourcesSearch,
23
+ ResourcesRemove,
24
+ ResourcesUpdateContent,
25
+ ResourcesMove,
26
+ ResourcesRename,
27
+ AuthSignUp,
28
+ AuthSignIn,
29
+ AuthVerifySignIn,
30
+ AuthVerifyInvitation,
31
+ AuthGetAuthenticatedUser,
32
+ AuthGetAuthenticatedUserHistory,
33
+ AuthGetUser,
34
+ AuthSignOff,
35
+ WorkspacesGet,
36
+ WorkspacesGetCurrent,
37
+ UserCurrentGet,
38
+ UserCurrentGetHistory,
39
+ UserCurrentUpdate
40
+ } from './Actions';
41
+ import { SDKConfig } from './config'
42
+
43
+ export class SDK {
44
+
45
+ workspaceId?: string;
46
+ authorization?: string;
47
+ baseUrl = 'https://api.ossy.se/api/v0'
48
+
49
+ static of(config: SDKConfig) {
50
+ return new SDK(config)
51
+ }
52
+
53
+ constructor(config: SDKConfig) {
54
+ this.updateConfig(config)
55
+ }
56
+
57
+ updateConfig(intendedConfig: SDKConfig) {
58
+ this.baseUrl = intendedConfig.apiUrl || this.baseUrl
59
+ this.workspaceId = intendedConfig.workspaceId || this.workspaceId
60
+ this.authorization = intendedConfig.authorization || this.authorization
61
+ }
62
+
63
+ get apiTokens() {
64
+ return {
65
+ list: this.makeRequest(ApiTokenGetAll).bind(this),
66
+ create: this.makeRequest(ApiTokenCreate).bind(this),
67
+ invalidate: this.makeRequest(ApiTokenInvalidate).bind(this)
68
+ }
69
+ }
70
+
71
+ get workspaces() {
72
+ return {
73
+ current: this.makeRequest(WorkspacesGetCurrent).bind(this),
74
+ list: this.makeRequest(WorkspacesList).bind(this),
75
+ get: this.makeRequest(WorkspacesGet).bind(this),
76
+ create: this.makeRequest(WorkspacesCreate).bind(this),
77
+ importResourceTemplates: this.makeRequest(WorkspacesImportResourceTemplates).bind(this),
78
+ getResourceTemplates: this.makeRequest(WorkspacesGetResourceTemplates).bind(this),
79
+ createApiToken: this.makeRequest(WorkspacesCreateApiToken).bind(this),
80
+ getApiTokens: this.makeRequest(WorkspacesGetApiTokens).bind(this),
81
+ inviteUser: this.makeRequest(WorkspacesInviteUser).bind(this),
82
+ enableService: this.makeRequest(WorkspacesEnableService).bind(this),
83
+ disableService: this.makeRequest(WorkspacesDisableService).bind(this),
84
+ };
85
+ }
86
+
87
+ get users () {
88
+ return {
89
+ list: this.makeRequest(WorkspacesGetUsers).bind(this),
90
+ }
91
+ }
92
+
93
+ get currentUser () {
94
+ return {
95
+ get: this.makeRequest(UserCurrentGet).bind(this),
96
+ update: this.makeRequest(UserCurrentUpdate).bind(this),
97
+ history: this.makeRequest(UserCurrentGetHistory).bind(this),
98
+ }
99
+ }
100
+
101
+ get resources() {
102
+ return {
103
+ createDirectory: this.makeRequest(ResourcesCreateDirectory).bind(this),
104
+ create: this.makeRequest(ResourcesCreate).bind(this),
105
+ upload: ({ location = '/', file }: { location: string; file: File} ) => {
106
+ const payload = {
107
+ type: file.type,
108
+ location: location,
109
+ name: file.name,
110
+ size: file.size
111
+ }
112
+ return this.makeRequest(ResourcesUpload)(payload)
113
+ .then(resource => {
114
+ return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
115
+ .then(() => resource)
116
+ })
117
+ },
118
+ uploadNamedVersion: ({ id, name, file }: { id: string, name: string, file: File }) => {
119
+ const payload = {
120
+ id: id,
121
+ name: name,
122
+ size: file.size
123
+ }
124
+ this.makeRequest(ResourcesUploadNamedVersion)(payload)
125
+ .then(resource => {
126
+ return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
127
+ .then(() => resource)
128
+ })
129
+ },
130
+ get: this.makeRequest(ResourcesGet).bind(this),
131
+ list: (query: ({ location?: string; })) => {
132
+ const search = new URLSearchParams({ ...query }).toString()
133
+ return this.makeRequest(ResourcesList)({ search })
134
+ },
135
+ search: this.makeRequest(ResourcesSearch).bind(this),
136
+ remove: this.makeRequest(ResourcesRemove).bind(this),
137
+ updateContent: this.makeRequest(ResourcesUpdateContent).bind(this),
138
+ move: this.makeRequest(ResourcesMove).bind(this),
139
+ rename: this.makeRequest(ResourcesRename).bind(this),
140
+ };
141
+ }
142
+
143
+ get auth() {
144
+ return {
145
+ signUp: this.makeRequest(AuthSignUp).bind(this),
146
+ signIn: this.makeRequest(AuthSignIn).bind(this),
147
+ verifySignIn: this.makeRequest(AuthVerifySignIn).bind(this),
148
+ verifyInvitation: this.makeRequest(AuthVerifyInvitation).bind(this),
149
+ getAuthenticatedUser: this.makeRequest(AuthGetAuthenticatedUser).bind(this),
150
+ getAuthenticatedUserHistory: this.makeRequest(AuthGetAuthenticatedUserHistory).bind(this),
151
+ getUser: this.makeRequest(AuthGetUser).bind(this),
152
+ signOff: this.makeRequest(AuthSignOff).bind(this),
153
+ };
154
+ }
155
+
156
+ makeRequest = <T extends Action>(action: T) => {
157
+ return (_payload?: Required<T['payload']>) => {
158
+
159
+ let payload: Required<T['payload']> = {} as Required<T['payload']>;
160
+
161
+ if (!!_payload || action.payload) {
162
+ payload = {
163
+ ...(action.payload || {} as Required<T['payload']>),
164
+ ...(_payload || {} as Required<T['payload']>)
165
+ }
166
+ }
167
+
168
+ let baseUrl: string = 'apiUrl' in payload ? payload?.apiUrl as string : this.baseUrl
169
+ let workspaceId = 'workspaceId' in payload ? payload.workspaceId : this.workspaceId;
170
+ let authorization = 'authorization' in payload ? payload.authorization : this.authorization;
171
+ let body: string | undefined = undefined;
172
+ let endpoint = action.endpoint;
173
+
174
+ if (payload) {
175
+ body = JSON.stringify(payload);
176
+
177
+ const paramNames = (action.endpoint.match(/:([a-zA-Z0-9_]+)/g) || []).map(
178
+ param => param.slice(1) as keyof T['payload']
179
+ );
180
+
181
+ endpoint = paramNames.reduce(
182
+ (endpoint, paramName) => endpoint.replace(String(paramName), String(payload[paramName])),
183
+ action.endpoint
184
+ )
185
+ }
186
+
187
+ return fetch(`${baseUrl}${endpoint}`, {
188
+ credentials: 'include',
189
+ headers: {
190
+ 'Content-Type': 'application/json',
191
+ workspaceId: workspaceId as string,
192
+ Authorization: authorization as string
193
+
194
+ },
195
+ method: action.method,
196
+ body
197
+ }).then(response => {
198
+ const contentType = response.headers.get('Content-Type') || ''
199
+ const status = response.status
200
+ const okResponseCodes = [200, 204]
201
+ if (status === 400) return response.json().then(content => Promise.reject(content.error))
202
+ if (!okResponseCodes.includes(status)) return Promise.reject(response)
203
+ if (contentType.includes('application/json')) return response.json()
204
+ return response
205
+ })
206
+ }
207
+ }
208
+
209
+ }
210
+
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "es6",
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
+ "incremental": false,
15
+ "declaration": true,
16
+ "declarationDir": "./build/types"
17
+ },
18
+ "exclude": [
19
+ "build",
20
+ "node_modules",
21
+ "src/**/*.test.tsx",
22
+ "src/**/*.stories.tsx",
23
+ "rollup.config.js",
24
+ "src/data.mock.ts"
25
+ ]
26
+ }
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});class t{static of(e){return new t(e)}constructor(t){this.http=t?.http}signUp(t){return this.http.post("/users/sign-up",t)}signIn(t){return this.http.post("/users/sign-in",t)}verifySignIn(t){return this.http.get(`/users/verify-sign-in?token=${t}`)}verifyInvitation(t,e){return this.http.get(`/workspaces/${t}/invitations?token=${e}`)}getAuthenticatedUser(){return this.http.get("/users/me")}getAuthenticatedUserHistory(){return this.http.get("/users/me/history")}getUser(t){return this.http.get(`/users/${t}`)}signOff(){return this.http.get("/users/sign-off")}}const e={VisualContentDescriptors:"@ossy/jobs/visual-content-descriptors",ResizeCommonWeb:"@ossy/jobs/resize-common-web"},s={Queued:"queued",InProgress:"in progress",Success:"success",Failed:"failed"};class r{static location="/@ossy/jobs/";static of(t){return new r(t)}constructor(t){this.http=t?.http,this.resources=t?.resources}get(t={}){const e="string"==typeof t?{id:t}:t;return e.location=r.location,this.resources.search(e)}getUnprocessed(){return this.resources.search({$and:[{$or:[{"content.nextReevaluation":{$exists:!1}},{"content.nextReevaluation":null},{"content.nextReevaluation":{$lt:Date.now()}}]},{"content.status":{$in:["queued","failed"]}},{location:"/@ossy/jobs/"},{type:{$regex:"^@ossy/jobs"}}]})}create({type:t,resourceId:n}){if(!Object.values(e).includes(t))throw new Error(`Job type ${t} does not exist`);if(!n)throw new Error("Resource ID is required");return this.resources.create({type:t,location:r.location,name:`[${s.Queued}] ${n}`,content:{resourceId:n,status:s.Queued,result:void 0}})}}class n{static of(t){return new n(t)}constructor(t){this.http=t?.http}create({name:t,description:e,expiresAt:s}){return this.http.post("/users/me/tokens",{name:t,description:e,expiresAt:s})}getAll(){return this.http.get("/users/me/tokens")}invalidate(t){return this.http.delete(`/users/me/tokens/${t}`)}}class o{static of(t){return new o(t)}constructor(t){this.http=t?.http}createDirectory({location:t,name:e}){return this.http.post("/resources",{type:"directory",location:t,name:e})}createDocument(t){return this.create(t)}create(t){return this.http.post("/resources",{type:t.type,location:t.location,name:t.name,content:t.content})}upload({location:t="/",file:e}){return this.http.post("/resources",{type:e.type,location:t,name:e.name,size:e.size}).then((t=>fetch(t.content.uploadUrl,{method:"PUT",body:e}).then((()=>t))))}uploadNamedVersion({resourceId:t,name:e,file:s}){return this.http.put(`/resources/${t}/${e}`,{type:s.type,size:s.size}).then((t=>fetch(t.content.uploadUrl,{method:"PUT",body:s}).then((()=>t))))}byId(t){return this.http.get(`/resources/${t}`)}byLocation(t="/"){return this.http.get(`/resources?location=${t}`)}get(t={}){if("string"==typeof t)return this.byId(t);const e=new URLSearchParams(t).toString();return this.http.get(`/resources?${e}`)}search(t={}){return"string"==typeof t?this.byId(t):this.http.post("/resources/search",t)}remove(t){return this.http.delete(`/resources/${t}`)}updateContent(t,e){return this.http.put(`/resources/${t}/content`,e)}move(t,e){return this.http.put(`/resources/${t}/location`,e)}rename(t,e){return this.http.put(`/resources/${t}/name`,e)}}class i{static of(t){return new i(t)}constructor(t){this.http=t?.http,this.services={enable:t=>this.enableService(t),disable:t=>this.disableService(t)},this.details=()=>this.getUser(),this.history=()=>this.getHistory()}getUser(){return this.http.get("/users/me")}getHistory(){return this.http.get("/users/me/history")}update(t){return this.http.put("/users/me",t)}}class c{static of(t){return new c(t)}constructor(t){this.workspaceId=t?.workspaceId,this.http=t?.http,this.services={enable:t=>this.enableService(t),disable:t=>this.disableService(t)},this.users=()=>this.getUsers()}getAll(){return this.http.get("/workspaces")}byId(t){return this.http.get(`/workspaces/${t}`)}create(t){return this.http.post("/workspaces",t)}importResourceTempaltes(t,e){return this.http.post(`/workspaces/${t}/resource-templates`,e)}getResourceTemplates(t){return this.http.get(`/workspaces/${t}/resource-templates`)}createApiToken(t,e){return this.http.post(`/workspaces/${t}/tokens`,{workspaceId:t,description:e})}getApiTokens(t){return this.http.get(`/workspaces/${t}/tokens`)}inviteUser(t,e){return this.http.post(`/workspaces/${t}/invitations`,e)}enableService(t){return this.http.post("/services/enable",t)}disableService(t){return this.http.post("/services/disable",t)}getUsers(){return this.http.get(`/workspaces/${this.workspaceId}/users`)}}function h(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function u(t){return function e(s){return 0===arguments.length||h(s)?e:t.apply(this,arguments)}}function a(t){return function e(s,r){switch(arguments.length){case 0:return e;case 1:return h(s)?e:u((function(e){return t(s,e)}));default:return h(s)&&h(r)?e:h(s)?u((function(e){return t(e,r)})):h(r)?u((function(e){return t(s,e)})):t(s,r)}}}var p="function"==typeof Object.assign?Object.assign:function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e,s,r=Object(t),n=1,o=arguments.length;n<o;){var i=arguments[n];if(null!=i)for(var c in i)e=c,s=i,Object.prototype.hasOwnProperty.call(s,e)&&(r[c]=i[c]);n+=1}return r},l=a((function(t,e){return p({},t,e)}));const d={"Content-Type":"application/json",Accept:"application/json"};class f{static of(t){return new f(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...d,...t.headers})),"function"==typeof t?.headers&&(this.getHeaders=t.headers)}post(t,e){const s={method:"POST",body:JSON.stringify(e)};return this.fetch(t,s)}get(t){return this.fetch(t,{method:"GET"})}delete(t){return this.fetch(t,{method:"DELETE"})}put(t,e){const s={method:"PUT",body:JSON.stringify(e)};return this.fetch(t,s)}async fetch(t,e){const s={headers:await this.getHeaders(),credentials:"include"};return fetch(`${this.baseUrl}${t}`,l(e,s)).then((t=>{const e=t.headers.get("Content-Type")||"",s=t.status;return 400===s?t.json().then((t=>Promise.reject(t.error))):[200,204].includes(s)?e.includes("application/json")?t.json():t:Promise.reject(t)}))}}class g{static of(t){return new g(t)}constructor(t){this.updateConfig(t)}updateConfig(e){const s=this.config||{};this.config={...s,...e};const h=f.of({baseUrl:this.config?.apiUrl||"https://api.ossy.se/api/v0",headers:{workspaceId:this.config?.workspaceId,Authorization:this.config?.apiKey}});this.workspaceId=this.config.workspaceId,this.user=i.of({...this.config,http:h}),this.auth=t.of({...this.config,http:h}),this.workspaces=c.of({...this.config,http:h}),this.apiTokens=n.of({...this.config,http:h}),this.resources=o.of({...this.config,http:h}),this.jobs=r.of({...this.config,http:h,resources:this.resources})}}exports.JobStatus=s,exports.Jobs=e,exports.SDK=g;
@@ -1 +0,0 @@
1
- class t{static of(e){return new t(e)}constructor(t){this.http=t?.http}signUp(t){return this.http.post("/users/sign-up",t)}signIn(t){return this.http.post("/users/sign-in",t)}verifySignIn(t){return this.http.get(`/users/verify-sign-in?token=${t}`)}verifyInvitation(t,e){return this.http.get(`/workspaces/${t}/invitations?token=${e}`)}getAuthenticatedUser(){return this.http.get("/users/me")}getAuthenticatedUserHistory(){return this.http.get("/users/me/history")}getUser(t){return this.http.get(`/users/${t}`)}signOff(){return this.http.get("/users/sign-off")}}const e={VisualContentDescriptors:"@ossy/jobs/visual-content-descriptors",ResizeCommonWeb:"@ossy/jobs/resize-common-web"},s={Queued:"queued",InProgress:"in progress",Success:"success",Failed:"failed"};class r{static location="/@ossy/jobs/";static of(t){return new r(t)}constructor(t){this.http=t?.http,this.resources=t?.resources}get(t={}){const e="string"==typeof t?{id:t}:t;return e.location=r.location,this.resources.search(e)}getUnprocessed(){return this.resources.search({$and:[{$or:[{"content.nextReevaluation":{$exists:!1}},{"content.nextReevaluation":null},{"content.nextReevaluation":{$lt:Date.now()}}]},{"content.status":{$in:["queued","failed"]}},{location:"/@ossy/jobs/"},{type:{$regex:"^@ossy/jobs"}}]})}create({type:t,resourceId:n}){if(!Object.values(e).includes(t))throw new Error(`Job type ${t} does not exist`);if(!n)throw new Error("Resource ID is required");return this.resources.create({type:t,location:r.location,name:`[${s.Queued}] ${n}`,content:{resourceId:n,status:s.Queued,result:void 0}})}}class n{static of(t){return new n(t)}constructor(t){this.http=t?.http}create({name:t,description:e,expiresAt:s}){return this.http.post("/users/me/tokens",{name:t,description:e,expiresAt:s})}getAll(){return this.http.get("/users/me/tokens")}invalidate(t){return this.http.delete(`/users/me/tokens/${t}`)}}class o{static of(t){return new o(t)}constructor(t){this.http=t?.http}createDirectory({location:t,name:e}){return this.http.post("/resources",{type:"directory",location:t,name:e})}createDocument(t){return this.create(t)}create(t){return this.http.post("/resources",{type:t.type,location:t.location,name:t.name,content:t.content})}upload({location:t="/",file:e}){return this.http.post("/resources",{type:e.type,location:t,name:e.name,size:e.size}).then((t=>fetch(t.content.uploadUrl,{method:"PUT",body:e}).then((()=>t))))}uploadNamedVersion({resourceId:t,name:e,file:s}){return this.http.put(`/resources/${t}/${e}`,{type:s.type,size:s.size}).then((t=>fetch(t.content.uploadUrl,{method:"PUT",body:s}).then((()=>t))))}byId(t){return this.http.get(`/resources/${t}`)}byLocation(t="/"){return this.http.get(`/resources?location=${t}`)}get(t={}){if("string"==typeof t)return this.byId(t);const e=new URLSearchParams(t).toString();return this.http.get(`/resources?${e}`)}search(t={}){return"string"==typeof t?this.byId(t):this.http.post("/resources/search",t)}remove(t){return this.http.delete(`/resources/${t}`)}updateContent(t,e){return this.http.put(`/resources/${t}/content`,e)}move(t,e){return this.http.put(`/resources/${t}/location`,e)}rename(t,e){return this.http.put(`/resources/${t}/name`,e)}}class i{static of(t){return new i(t)}constructor(t){this.http=t?.http,this.services={enable:t=>this.enableService(t),disable:t=>this.disableService(t)},this.details=()=>this.getUser(),this.history=()=>this.getHistory()}getUser(){return this.http.get("/users/me")}getHistory(){return this.http.get("/users/me/history")}update(t){return this.http.put("/users/me",t)}}class c{static of(t){return new c(t)}constructor(t){this.workspaceId=t?.workspaceId,this.http=t?.http,this.services={enable:t=>this.enableService(t),disable:t=>this.disableService(t)},this.users=()=>this.getUsers()}getAll(){return this.http.get("/workspaces")}byId(t){return this.http.get(`/workspaces/${t}`)}create(t){return this.http.post("/workspaces",t)}importResourceTempaltes(t,e){return this.http.post(`/workspaces/${t}/resource-templates`,e)}getResourceTemplates(t){return this.http.get(`/workspaces/${t}/resource-templates`)}createApiToken(t,e){return this.http.post(`/workspaces/${t}/tokens`,{workspaceId:t,description:e})}getApiTokens(t){return this.http.get(`/workspaces/${t}/tokens`)}inviteUser(t,e){return this.http.post(`/workspaces/${t}/invitations`,e)}enableService(t){return this.http.post("/services/enable",t)}disableService(t){return this.http.post("/services/disable",t)}getUsers(){return this.http.get(`/workspaces/${this.workspaceId}/users`)}}function h(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function u(t){return function e(s){return 0===arguments.length||h(s)?e:t.apply(this,arguments)}}function a(t){return function e(s,r){switch(arguments.length){case 0:return e;case 1:return h(s)?e:u((function(e){return t(s,e)}));default:return h(s)&&h(r)?e:h(s)?u((function(e){return t(e,r)})):h(r)?u((function(e){return t(s,e)})):t(s,r)}}}var p="function"==typeof Object.assign?Object.assign:function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e,s,r=Object(t),n=1,o=arguments.length;n<o;){var i=arguments[n];if(null!=i)for(var c in i)e=c,s=i,Object.prototype.hasOwnProperty.call(s,e)&&(r[c]=i[c]);n+=1}return r},l=a((function(t,e){return p({},t,e)}));const d={"Content-Type":"application/json",Accept:"application/json"};class f{static of(t){return new f(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...d,...t.headers})),"function"==typeof t?.headers&&(this.getHeaders=t.headers)}post(t,e){const s={method:"POST",body:JSON.stringify(e)};return this.fetch(t,s)}get(t){return this.fetch(t,{method:"GET"})}delete(t){return this.fetch(t,{method:"DELETE"})}put(t,e){const s={method:"PUT",body:JSON.stringify(e)};return this.fetch(t,s)}async fetch(t,e){const s={headers:await this.getHeaders(),credentials:"include"};return fetch(`${this.baseUrl}${t}`,l(e,s)).then((t=>{const e=t.headers.get("Content-Type")||"",s=t.status;return 400===s?t.json().then((t=>Promise.reject(t.error))):[200,204].includes(s)?e.includes("application/json")?t.json():t:Promise.reject(t)}))}}class g{static of(t){return new g(t)}constructor(t){this.updateConfig(t)}updateConfig(e){const s=this.config||{};this.config={...s,...e};const h=f.of({baseUrl:this.config?.apiUrl||"https://api.ossy.se/api/v0",headers:{workspaceId:this.config?.workspaceId,Authorization:this.config?.apiKey}});this.workspaceId=this.config.workspaceId,this.user=i.of({...this.config,http:h}),this.auth=t.of({...this.config,http:h}),this.workspaces=c.of({...this.config,http:h}),this.apiTokens=n.of({...this.config,http:h}),this.resources=o.of({...this.config,http:h}),this.jobs=r.of({...this.config,http:h,resources:this.resources})}}export{s as JobStatus,e as Jobs,g as SDK};
@@ -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
- }
@@ -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
- }
@@ -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,47 +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
-
47
-
@@ -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
- }
@@ -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
- `/workspaces/${workspaceId}/resource-templates`,
35
- templates
36
- )
37
- }
38
-
39
- getResourceTemplates(workspaceId) {
40
- return this.http.get(
41
- `/workspaces/${workspaceId}/resource-templates`
42
- )
43
- }
44
-
45
- createApiToken(workspaceId, description) {
46
- return this.http.post(
47
- `/workspaces/${workspaceId}/tokens`,
48
- { workspaceId, description }
49
- )
50
- }
51
-
52
- getApiTokens(workspaceId) {
53
- return this.http.get(
54
- `/workspaces/${workspaceId}/tokens`
55
- )
56
- }
57
-
58
- inviteUser(workspaceId, email) {
59
- return this.http.post(
60
- `/workspaces/${workspaceId}/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
- `/workspaces/${this.workspaceId}/users`
82
- )
83
- }
84
-
85
- }