@ossy/sdk 0.0.10-alpha → 0.0.10

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,72 @@
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.10 (2025-10-25)
7
+
8
+ **Note:** Version bump only for package @ossy/sdk
9
+
10
+
11
+
12
+
13
+
14
+ ## 0.0.9 (2025-10-25)
15
+
16
+ **Note:** Version bump only for package @ossy/sdk
17
+
18
+
19
+
20
+
21
+
22
+ ## 0.0.8 (2025-10-25)
23
+
24
+ **Note:** Version bump only for package @ossy/sdk
25
+
26
+
27
+
28
+
29
+
30
+ ## 0.0.7 (2025-10-25)
31
+
32
+ **Note:** Version bump only for package @ossy/sdk
33
+
34
+
35
+
36
+
37
+
38
+ ## 0.0.6 (2025-10-25)
39
+
40
+ **Note:** Version bump only for package @ossy/sdk
41
+
42
+
43
+
44
+
45
+
46
+ ## 0.0.5 (2025-10-25)
47
+
48
+ **Note:** Version bump only for package @ossy/sdk
49
+
50
+
51
+
52
+
53
+
54
+ ## 0.0.4 (2025-10-25)
55
+
56
+ **Note:** Version bump only for package @ossy/sdk
57
+
58
+
59
+
60
+
61
+
62
+ ## 0.0.3 (2025-10-25)
63
+
64
+ **Note:** Version bump only for package @ossy/sdk
65
+
66
+
67
+
68
+
69
+
70
+ ## 0.0.2 (2025-10-25)
71
+
72
+ **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.
@@ -1 +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")}}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.get(e)}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(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 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}`)}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)}}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)}}function c(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function u(t){return function e(s){return 0===arguments.length||c(s)?e:t.apply(this,arguments)}}function h(t){return function e(s,r){switch(arguments.length){case 0:return e;case 1:return c(s)?e:u((function(e){return t(s,e)}));default:return c(s)&&c(r)?e:c(s)?u((function(e){return t(e,r)})):c(r)?u((function(e){return t(s,e)})):t(s,r)}}}function a(t,e){return Object.prototype.hasOwnProperty.call(e,t)}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=Object(t),s=1,r=arguments.length;s<r;){var n=arguments[s];if(null!=n)for(var o in n)a(o,n)&&(e[o]=n[o]);s+=1}return e},l=h((function(t,e){return p({},t,e)}));const f={"Content-Type":"application/json",Accept:"application/json"};class d{static of(t){return new d(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...f,...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 c=d.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.auth=t.of({...this.config,http:c}),this.workspaces=i.of({...this.config,http:c}),this.apiTokens=n.of({...this.config,http:c}),this.resources=o.of({...this.config,http:c}),this.jobs=r.of({...this.config,http:c,resources:this.resources})}}exports.JobStatus=s,exports.Jobs=e,exports.SDK=g;
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("/resource-templates",e)}getResourceTemplates(t){return this.http.get("/resource-templates")}createApiToken(t,e){return this.http.post("/tokens",{workspaceId:t,description:e})}getApiTokens(t){return this.http.get("/tokens")}inviteUser(t,e){return this.http.post("/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("/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)}}}function p(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var l="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)p(o,n)&&(e[o]=n[o]);s+=1}return e},d=a(function(t,e){return l({},t,e)});const f={"Content-Type":"application/json",Accept:"application/json"};class g{static of(t){return new g(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...f,...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}`,d(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 y{static of(t){return new y(t)}constructor(t){this.updateConfig(t)}updateConfig(e){const s=this.config||{};this.config={...s,...e};const h=g.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=y;
@@ -1 +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")}}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.get(e)}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(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 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}`)}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)}}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)}}function c(t){return null!=t&&"object"==typeof t&&!0===t["@@functional/placeholder"]}function h(t){return function e(s){return 0===arguments.length||c(s)?e:t.apply(this,arguments)}}function u(t){return function e(s,r){switch(arguments.length){case 0:return e;case 1:return c(s)?e:h((function(e){return t(s,e)}));default:return c(s)&&c(r)?e:c(s)?h((function(e){return t(e,r)})):c(r)?h((function(e){return t(s,e)})):t(s,r)}}}function a(t,e){return Object.prototype.hasOwnProperty.call(e,t)}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=Object(t),s=1,r=arguments.length;s<r;){var n=arguments[s];if(null!=n)for(var o in n)a(o,n)&&(e[o]=n[o]);s+=1}return e},l=u((function(t,e){return p({},t,e)}));const f={"Content-Type":"application/json",Accept:"application/json"};class d{static of(t){return new d(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...f,...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 c=d.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.auth=t.of({...this.config,http:c}),this.workspaces=i.of({...this.config,http:c}),this.apiTokens=n.of({...this.config,http:c}),this.resources=o.of({...this.config,http:c}),this.jobs=r.of({...this.config,http:c,resources:this.resources})}}export{s as JobStatus,e as Jobs,g as SDK};
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("/resource-templates",e)}getResourceTemplates(t){return this.http.get("/resource-templates")}createApiToken(t,e){return this.http.post("/tokens",{workspaceId:t,description:e})}getApiTokens(t){return this.http.get("/tokens")}inviteUser(t,e){return this.http.post("/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("/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)}}}function p(t,e){return Object.prototype.hasOwnProperty.call(e,t)}var l="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)p(o,n)&&(e[o]=n[o]);s+=1}return e},d=a(function(t,e){return l({},t,e)});const f={"Content-Type":"application/json",Accept:"application/json"};class g{static of(t){return new g(t)}constructor(t){this.baseUrl=t.baseUrl,"object"==typeof t?.headers&&(this.getHeaders=()=>Promise.resolve({...f,...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}`,d(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 y{static of(t){return new y(t)}constructor(t){this.updateConfig(t)}updateConfig(e){const s=this.config||{};this.config={...s,...e};const h=g.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,y as SDK};
package/package.json CHANGED
@@ -1,44 +1,36 @@
1
1
  {
2
2
  "name": "@ossy/sdk",
3
3
  "description": "Sofware Development Kit for interactive with our services",
4
- "version": "0.0.10-alpha",
5
- "url": "git://github.com/ossy-se/ossy.git",
4
+ "version": "0.0.10",
5
+ "url": "git://github.com/ossy-se/packages/sdk",
6
6
  "source": "src/index.js",
7
- "type": "module",
8
7
  "main": "build/index.cjs.js",
9
8
  "module": "build/index.esm.js",
10
9
  "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
10
+ "repository": "github:ossy-se/packages",
11
+ "license": "MIT License",
11
12
  "scripts": {
12
13
  "start": "",
13
- "build": "rm -rf && rollup -c rollup.config.js",
14
+ "build": "rollup -c rollup.config.js",
14
15
  "test": ""
15
16
  },
16
- "browserslist": {
17
- "production": [
18
- ">0.2%",
19
- "not dead",
20
- "not op_mini all"
21
- ],
22
- "development": [
23
- "last 1 chrome version",
24
- "last 1 firefox version",
25
- "last 1 safari version"
26
- ]
27
- },
28
17
  "dependencies": {
29
- "jwt-decode": "^3.1.2",
30
- "ramda": "^0.27.1"
18
+ "ramda": "^0.32.0"
31
19
  },
32
20
  "devDependencies": {
33
21
  "@babel/core": "^7.14.5",
34
22
  "@babel/eslint-parser": "^7.15.8",
35
23
  "@babel/preset-react": "^7.14.5",
36
- "@rollup/plugin-commonjs": "^21.0.1",
37
- "@rollup/plugin-node-resolve": "^13.0.0",
38
- "babel-loader": "^8.2.2",
39
- "rollup": "^2.37.1",
24
+ "@rollup/plugin-commonjs": "^28.0.9",
25
+ "@rollup/plugin-node-resolve": "^16.0.3",
26
+ "babel-loader": "^10.0.0",
27
+ "rollup": "^4.52.5",
40
28
  "rollup-plugin-babel": "^4.4.0",
41
29
  "rollup-plugin-peer-deps-external": "^2.2.4",
42
30
  "rollup-plugin-terser": "^7.0.2"
43
- }
31
+ },
32
+ "publishConfig": {
33
+ "access": "public"
34
+ },
35
+ "gitHead": "22ec3583362a630a927d9b7d0275787990062fdf"
44
36
  }
@@ -8,8 +8,8 @@ export class ApiTokensClient {
8
8
  this.http = config?.http
9
9
  }
10
10
 
11
- create(description) {
12
- return this.http.post('/users/me/tokens', description)
11
+ create({ name, description, expiresAt }) {
12
+ return this.http.post('/users/me/tokens', { name, description, expiresAt })
13
13
  }
14
14
 
15
15
  getAll() {
@@ -11,7 +11,7 @@ export const JobStatus = {
11
11
  }
12
12
 
13
13
  export class JobsClient {
14
- static location = '@ossy/jobs'
14
+ static location = '/@ossy/jobs/'
15
15
 
16
16
  static of(config) {
17
17
  return new JobsClient(config)
@@ -25,7 +25,24 @@ export class JobsClient {
25
25
  get(_query = {}) {
26
26
  const query = typeof _query === 'string' ? { id: _query } : _query
27
27
  query.location = JobsClient.location
28
- return this.resources.get(query)
28
+ return this.resources.search(query)
29
+ }
30
+
31
+ getUnprocessed() {
32
+ return this.resources.search({
33
+ $and: [
34
+ {
35
+ $or: [
36
+ { "content.nextReevaluation": { $exists: false } },
37
+ { "content.nextReevaluation": null },
38
+ { "content.nextReevaluation": { $lt: Date.now() } }
39
+ ]
40
+ },
41
+ { 'content.status': { $in: ['queued', 'failed'] } },
42
+ { "location": "/@ossy/jobs/" },
43
+ { "type": { $regex: "^@ossy/jobs" } }
44
+ ]
45
+ })
29
46
  }
30
47
 
31
48
  create({ type, resourceId }) {
@@ -73,6 +73,16 @@ export class ResourcesClient {
73
73
  return this.http.get(`/resources?${search}`)
74
74
  }
75
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
+
76
86
  remove(resourceId) {
77
87
  return this.http.delete(`/resources/${resourceId}`)
78
88
  }
package/src/sdk.js CHANGED
@@ -2,6 +2,7 @@ import { AuthClient } from './auth-client.js'
2
2
  import { JobsClient } from './jobs-client.js'
3
3
  import { ApiTokensClient } from './api-tokens-client.js'
4
4
  import { ResourcesClient } from './resources-client.js'
5
+ import { UserClient } from './user-client.js'
5
6
  import { WorkspacesClient } from './workspaces-client.js'
6
7
  import { Http } from './http.js'
7
8
 
@@ -32,6 +33,7 @@ export class SDK {
32
33
  })
33
34
 
34
35
  this.workspaceId = this.config.workspaceId
36
+ this.user = UserClient.of({ ...this.config, http })
35
37
  this.auth = AuthClient.of({ ...this.config, http })
36
38
  this.workspaces = WorkspacesClient.of({ ...this.config, http })
37
39
  this.apiTokens = ApiTokensClient.of({ ...this.config, http })
@@ -0,0 +1,32 @@
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
+ }
@@ -5,12 +5,16 @@ export class WorkspacesClient {
5
5
  }
6
6
 
7
7
  constructor(config) {
8
+ this.workspaceId = config?.workspaceId
8
9
  this.http = config?.http
9
10
 
10
11
  this.services = {
11
12
  enable: x => this.enableService(x),
12
13
  disable: x => this.disableService(x)
13
14
  }
15
+
16
+ this.users = () => this.getUsers()
17
+
14
18
  }
15
19
 
16
20
  getAll() {
@@ -27,33 +31,33 @@ export class WorkspacesClient {
27
31
 
28
32
  importResourceTempaltes(workspaceId, templates) {
29
33
  return this.http.post(
30
- `/workspaces/${workspaceId}/resource-templates`,
34
+ `/resource-templates`,
31
35
  templates
32
36
  )
33
37
  }
34
38
 
35
39
  getResourceTemplates(workspaceId) {
36
40
  return this.http.get(
37
- `/workspaces/${workspaceId}/resource-templates`
41
+ `/resource-templates`
38
42
  )
39
43
  }
40
44
 
41
45
  createApiToken(workspaceId, description) {
42
46
  return this.http.post(
43
- `/workspaces/${workspaceId}/tokens`,
47
+ `/tokens`,
44
48
  { workspaceId, description }
45
49
  )
46
50
  }
47
51
 
48
52
  getApiTokens(workspaceId) {
49
53
  return this.http.get(
50
- `/workspaces/${workspaceId}/tokens`
54
+ `/tokens`
51
55
  )
52
56
  }
53
57
 
54
58
  inviteUser(workspaceId, email) {
55
59
  return this.http.post(
56
- `/workspaces/${workspaceId}/invitations`,
60
+ `/invitations`,
57
61
  email
58
62
  )
59
63
  }
@@ -72,4 +76,10 @@ export class WorkspacesClient {
72
76
  )
73
77
  }
74
78
 
79
+ getUsers() {
80
+ return this.http.get(
81
+ `/users`
82
+ )
83
+ }
84
+
75
85
  }
package/src/playground.js DELETED
@@ -1,14 +0,0 @@
1
- import { SDK } from './index.js'
2
-
3
- const sdk = SDK.of({
4
- apiUrl: 'http://localhost:3001/api/v0',
5
- workspaceId: 'WQLqogbN2CgnQISD-aD7a',
6
- apiKey: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0b2tlbklkIjoieDZLdURZLUZMWUNLVTFuTUYxVVlpIiwiaWF0IjoxNzEyMzE0MDI4LCJleHAiOjE3MTI5MTg4Mjh9.xSM6dakkjhk9plgi1LTvUfisZQHqcy4pMhDfZ1vRmKo'
7
- })
8
-
9
- async function main() {
10
- const jobs = await sdk.jobs.get()
11
- console.log(jobs)
12
- }
13
-
14
- main()