@ossy/sdk 0.0.1-alpha

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/README.md ADDED
@@ -0,0 +1 @@
1
+ # @ossy/sdk
@@ -0,0 +1 @@
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")}}class e{static of(t){return new e(t)}constructor(t){this.http=t?.http}create(t){return this.http.post("/users/me/tokens",t)}getAll(){return this.http.get("/users/me/tokens")}invalidate(t){return this.http.delete(`/users/me/tokens/${t}`)}}class s{static of(t){return new s(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.http.post("/resources",{type:t.type,location:t.location,name:t.name,content:t.content})}uploadFile({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))))}byId(t){return this.http.get(`/resources/${t}`)}byLocation(t="/"){return this.http.get(`/resources?location=${t}`)}byQuery(t){return this.http.get("/resources"+(t?`?${t}`:""))}remove(t){return this.http.delete(`/resources/${t}`)}updateResourceContent(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 r{static of(t){return new r(t)}constructor(t){this.http=t?.http}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)}}function n(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function o(t){return function e(s){return 0===arguments.length||n(s)?e:t.apply(this,arguments)}}function i(t){return function e(s,r){switch(arguments.length){case 0:return e;case 1:return n(s)?e:o((function(e){return t(s,e)}));default:return n(s)&&n(r)?e:n(s)?o((function(e){return t(e,r)})):n(r)?o((function(e){return t(s,e)})):t(s,r)}}}function c(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var h="function"==typeof Object.assign?Object.assign:function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),s=1,r=arguments.length;s<r;){var n=arguments[s];if(null!=n)for(var o in n)c(o,n)&&(e[o]=n[o]);s+=1}return e},u=i((function(t,e){return h({},t,e)}));const p={"Content-Type":"application/json",Accept:"application/json"};class a{static of(t){return new a(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...p,...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}`,u(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 f{static of(t){return new f(t)}constructor(t){this.updateConfig(t)}updateConfig(n){const o=this.config||{};this.config={...o,...n};const i=a.of({baseUrl:this.config.apiUrl||"https://api.ossy.se/api/v0",headers:{workspaceId:this.config.workspaceId}});this.workspaceId=this.config.workspaceId,this.auth=t.of({...this.config,http:i}),this.apiTokens=e.of({...this.config,http:i}),this.resources=s.of({...this.config,http:i}),this.workspaces=r.of({...this.config,http:i})}}exports.SDK=f;
@@ -0,0 +1 @@
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")}}class e{static of(t){return new e(t)}constructor(t){this.http=t?.http}create(t){return this.http.post("/users/me/tokens",t)}getAll(){return this.http.get("/users/me/tokens")}invalidate(t){return this.http.delete(`/users/me/tokens/${t}`)}}class s{static of(t){return new s(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.http.post("/resources",{type:t.type,location:t.location,name:t.name,content:t.content})}uploadFile({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))))}byId(t){return this.http.get(`/resources/${t}`)}byLocation(t="/"){return this.http.get(`/resources?location=${t}`)}byQuery(t){return this.http.get("/resources"+(t?`?${t}`:""))}remove(t){return this.http.delete(`/resources/${t}`)}updateResourceContent(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 r{static of(t){return new r(t)}constructor(t){this.http=t?.http}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)}}function n(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function o(t){return function e(s){return 0===arguments.length||n(s)?e:t.apply(this,arguments)}}function i(t){return function e(s,r){switch(arguments.length){case 0:return e;case 1:return n(s)?e:o((function(e){return t(s,e)}));default:return n(s)&&n(r)?e:n(s)?o((function(e){return t(e,r)})):n(r)?o((function(e){return t(s,e)})):t(s,r)}}}function c(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var h="function"==typeof Object.assign?Object.assign:function(t){if(null==t)throw new TypeError("Cannot convert undefined or null to object");for(var e=Object(t),s=1,r=arguments.length;s<r;){var n=arguments[s];if(null!=n)for(var o in n)c(o,n)&&(e[o]=n[o]);s+=1}return e},u=i((function(t,e){return h({},t,e)}));const p={"Content-Type":"application/json",Accept:"application/json"};class a{static of(t){return new a(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...p,...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}`,u(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 f{static of(t){return new f(t)}constructor(t){this.updateConfig(t)}updateConfig(n){const o=this.config||{};this.config={...o,...n};const i=a.of({baseUrl:this.config.apiUrl||"https://api.ossy.se/api/v0",headers:{workspaceId:this.config.workspaceId}});this.workspaceId=this.config.workspaceId,this.auth=t.of({...this.config,http:i}),this.apiTokens=e.of({...this.config,http:i}),this.resources=s.of({...this.config,http:i}),this.workspaces=r.of({...this.config,http:i})}}export{f as SDK};
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@ossy/sdk",
3
+ "description": "Sofware Development Kit for interactive with our services",
4
+ "version": "0.0.1-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",
9
+ "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
10
+ "scripts": {
11
+ "start": "",
12
+ "build": "rm -rf && rollup -c rollup.config.js",
13
+ "test": ""
14
+ },
15
+ "browserslist": {
16
+ "production": [
17
+ ">0.2%",
18
+ "not dead",
19
+ "not op_mini all"
20
+ ],
21
+ "development": [
22
+ "last 1 chrome version",
23
+ "last 1 firefox version",
24
+ "last 1 safari version"
25
+ ]
26
+ },
27
+ "dependencies": {
28
+ "jwt-decode": "^3.1.2",
29
+ "ramda": "^0.27.1"
30
+ },
31
+ "devDependencies": {
32
+ "@babel/core": "^7.14.5",
33
+ "@babel/eslint-parser": "^7.15.8",
34
+ "@babel/preset-react": "^7.14.5",
35
+ "@rollup/plugin-commonjs": "^21.0.1",
36
+ "@rollup/plugin-node-resolve": "^13.0.0",
37
+ "babel-loader": "^8.2.2",
38
+ "rollup": "^2.37.1",
39
+ "rollup-plugin-babel": "^4.4.0",
40
+ "rollup-plugin-peer-deps-external": "^2.2.4",
41
+ "rollup-plugin-terser": "^7.0.2"
42
+ }
43
+ }
@@ -0,0 +1,30 @@
1
+ import babel from 'rollup-plugin-babel'
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve'
3
+ 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'
7
+
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
+ }
@@ -0,0 +1,23 @@
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(description) {
12
+ return this.http.post('/users/me/tokens', description)
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
+ }
@@ -0,0 +1,43 @@
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 ADDED
@@ -0,0 +1,82 @@
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/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './sdk.js'
@@ -0,0 +1,75 @@
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
+ createDocument(document) {
20
+ return this.http.post(`/resources`, {
21
+ type: document.type,
22
+ location: document.location,
23
+ name: document.name,
24
+ content: document.content
25
+ })
26
+ }
27
+
28
+ uploadFile({ location, file }) {
29
+ return this.http.post(`/resources`, {
30
+ type: file.type,
31
+ location: location,
32
+ name: file.name,
33
+ size: file.size
34
+ })
35
+ .then(resource => {
36
+ return fetch(resource.content.uploadUrl, { method: 'PUT', body: file })
37
+ .then(() => resource)
38
+ })
39
+ }
40
+
41
+ byId(resourceId) {
42
+ return this.http.get(`/resources/${resourceId}`)
43
+ }
44
+
45
+ byLocation(location = '/') {
46
+ return this.http.get(`/resources?location=${location}`)
47
+ }
48
+
49
+ byQuery(query) {
50
+ return this.http.get(`/resources${!!query ? `?${query}` : ''}`)
51
+ }
52
+
53
+ remove(resourceId) {
54
+ return this.http.delete(`/resources/${resourceId}`)
55
+ }
56
+
57
+ updateResourceContent(resourceId, resourceContent) {
58
+ return this.http.put(`/resources/${resourceId}/content`, resourceContent)
59
+ }
60
+
61
+ move(resourceId, newLocation) {
62
+ return this.http.put(
63
+ `/resources/${resourceId}/location`,
64
+ newLocation
65
+ )
66
+ }
67
+
68
+ rename(resourceId, newName) {
69
+ return this.http.put(
70
+ `/resources/${resourceId}/name`,
71
+ newName
72
+ )
73
+ }
74
+
75
+ }
package/src/sdk.js ADDED
@@ -0,0 +1,39 @@
1
+ import { AuthClient } from './auth-client.js'
2
+ import { ApiTokensClient } from './api-tokens-client.js'
3
+ import { ResourcesClient } from './resources-client.js'
4
+ import { WorkspacesClient } from './workspaces-client.js'
5
+ import { Http } from './http.js'
6
+
7
+ export class SDK {
8
+
9
+ static of(config) {
10
+ return new SDK(config)
11
+ }
12
+
13
+ constructor(config) {
14
+ this.updateConfig(config)
15
+ }
16
+
17
+ updateConfig(intendedConfig) {
18
+ const oldConfig = this.config || {}
19
+
20
+ this.config = {
21
+ ...oldConfig,
22
+ ...intendedConfig
23
+ }
24
+
25
+ const http = Http.of({
26
+ baseUrl: this.config.apiUrl || 'https://api.ossy.se/api/v0',
27
+ headers: { workspaceId: this.config.workspaceId }
28
+ })
29
+
30
+ this.workspaceId = this.config.workspaceId
31
+ this.auth = AuthClient.of({ ...this.config, http })
32
+ this.apiTokens = ApiTokensClient.of({ ...this.config, http })
33
+ this.resources = ResourcesClient.of({ ...this.config, http })
34
+ this.workspaces = WorkspacesClient.of({ ...this.config, http })
35
+ }
36
+
37
+ }
38
+
39
+
@@ -0,0 +1,56 @@
1
+ export class WorkspacesClient {
2
+
3
+ static of(config) {
4
+ return new WorkspacesClient(config)
5
+ }
6
+
7
+ constructor(config) {
8
+ this.http = config?.http
9
+ }
10
+
11
+ getAll() {
12
+ return this.http.get('/workspaces')
13
+ }
14
+
15
+ byId(workspaceId) {
16
+ return this.http.get(`/workspaces/${workspaceId}`)
17
+ }
18
+
19
+ create(workspaceName) {
20
+ return this.http.post('/workspaces', workspaceName)
21
+ }
22
+
23
+ importResourceTempaltes(workspaceId, templates) {
24
+ return this.http.post(
25
+ `/workspaces/${workspaceId}/resource-templates`,
26
+ templates
27
+ )
28
+ }
29
+
30
+ getResourceTemplates(workspaceId) {
31
+ return this.http.get(
32
+ `/workspaces/${workspaceId}/resource-templates`
33
+ )
34
+ }
35
+
36
+ createApiToken(workspaceId, description) {
37
+ return this.http.post(
38
+ `/workspaces/${workspaceId}/tokens`,
39
+ { workspaceId, description }
40
+ )
41
+ }
42
+
43
+ getApiTokens(workspaceId) {
44
+ return this.http.get(
45
+ `/workspaces/${workspaceId}/tokens`
46
+ )
47
+ }
48
+
49
+ inviteUser(workspaceId, email) {
50
+ return this.http.post(
51
+ `/workspaces/${workspaceId}/invitations`,
52
+ email
53
+ )
54
+ }
55
+
56
+ }