@ossy/sdk 0.0.16-alpha → 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 ADDED
@@ -0,0 +1,120 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ ## 0.0.16 (2025-10-30)
7
+
8
+ **Note:** Version bump only for package @ossy/sdk
9
+
10
+
11
+
12
+
13
+
14
+ ## 0.0.15 (2025-10-27)
15
+
16
+ **Note:** Version bump only for package @ossy/sdk
17
+
18
+
19
+
20
+
21
+
22
+ ## 0.0.14 (2025-10-27)
23
+
24
+ **Note:** Version bump only for package @ossy/sdk
25
+
26
+
27
+
28
+
29
+
30
+ ## 0.0.13 (2025-10-27)
31
+
32
+ **Note:** Version bump only for package @ossy/sdk
33
+
34
+
35
+
36
+
37
+
38
+ ## 0.0.12 (2025-10-27)
39
+
40
+ **Note:** Version bump only for package @ossy/sdk
41
+
42
+
43
+
44
+
45
+
46
+ ## 0.0.11 (2025-10-27)
47
+
48
+ **Note:** Version bump only for package @ossy/sdk
49
+
50
+
51
+
52
+
53
+
54
+ ## 0.0.10 (2025-10-25)
55
+
56
+ **Note:** Version bump only for package @ossy/sdk
57
+
58
+
59
+
60
+
61
+
62
+ ## 0.0.9 (2025-10-25)
63
+
64
+ **Note:** Version bump only for package @ossy/sdk
65
+
66
+
67
+
68
+
69
+
70
+ ## 0.0.8 (2025-10-25)
71
+
72
+ **Note:** Version bump only for package @ossy/sdk
73
+
74
+
75
+
76
+
77
+
78
+ ## 0.0.7 (2025-10-25)
79
+
80
+ **Note:** Version bump only for package @ossy/sdk
81
+
82
+
83
+
84
+
85
+
86
+ ## 0.0.6 (2025-10-25)
87
+
88
+ **Note:** Version bump only for package @ossy/sdk
89
+
90
+
91
+
92
+
93
+
94
+ ## 0.0.5 (2025-10-25)
95
+
96
+ **Note:** Version bump only for package @ossy/sdk
97
+
98
+
99
+
100
+
101
+
102
+ ## 0.0.4 (2025-10-25)
103
+
104
+ **Note:** Version bump only for package @ossy/sdk
105
+
106
+
107
+
108
+
109
+
110
+ ## 0.0.3 (2025-10-25)
111
+
112
+ **Note:** Version bump only for package @ossy/sdk
113
+
114
+
115
+
116
+
117
+
118
+ ## 0.0.2 (2025-10-25)
119
+
120
+ **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.0.16",
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": "6cf3fe944bcbd61a2deb8d2e24f982374415e6d4"
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,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
@@ -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,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/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
- }