@ossy/sdk 0.0.1-alpha → 0.0.1

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.
@@ -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")}}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;
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)}}}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 +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};
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)}}}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};
package/package.json CHANGED
@@ -1,31 +1,20 @@
1
1
  {
2
2
  "name": "@ossy/sdk",
3
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",
4
+ "version": "0.0.1",
5
+ "url": "git://github.com/ossy-se/packages/sdk",
6
6
  "source": "src/index.js",
7
7
  "main": "build/index.cjs.js",
8
8
  "module": "build/index.esm.js",
9
9
  "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
10
+ "repository": "github:ossy-se/packages",
11
+ "license": "MIT License",
10
12
  "scripts": {
11
13
  "start": "",
12
14
  "build": "rm -rf && rollup -c rollup.config.js",
13
15
  "test": ""
14
16
  },
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
17
  "dependencies": {
28
- "jwt-decode": "^3.1.2",
29
18
  "ramda": "^0.27.1"
30
19
  },
31
20
  "devDependencies": {
@@ -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() {
package/src/index.js CHANGED
@@ -1 +1,2 @@
1
- export * from './sdk.js'
1
+ export * from './sdk.js'
2
+ export { Jobs, JobStatus } from './jobs-client.js'
@@ -0,0 +1,66 @@
1
+ export const Jobs = {
2
+ VisualContentDescriptors: '@ossy/jobs/visual-content-descriptors',
3
+ ResizeCommonWeb: '@ossy/jobs/resize-common-web',
4
+ }
5
+
6
+ export const JobStatus = {
7
+ Queued: 'queued',
8
+ InProgress: 'in progress',
9
+ Success: 'success',
10
+ Failed: 'failed',
11
+ }
12
+
13
+ export class JobsClient {
14
+ static location = '/@ossy/jobs/'
15
+
16
+ static of(config) {
17
+ return new JobsClient(config)
18
+ }
19
+
20
+ constructor(config) {
21
+ this.http = config?.http
22
+ this.resources = config?.resources
23
+ }
24
+
25
+ get(_query = {}) {
26
+ const query = typeof _query === 'string' ? { id: _query } : _query
27
+ query.location = JobsClient.location
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
+ })
46
+ }
47
+
48
+ create({ type, resourceId }) {
49
+ const jobTypeExists = Object.values(Jobs).includes(type)
50
+ if (!jobTypeExists) throw new Error(`Job type ${type} does not exist`)
51
+ if (!resourceId) throw new Error(`Resource ID is required`)
52
+ return this.resources.create({
53
+ type,
54
+ location: JobsClient.location,
55
+ name: `[${JobStatus.Queued}] ${resourceId}`,
56
+ content: {
57
+ resourceId,
58
+ status: JobStatus.Queued,
59
+ result: undefined
60
+ }
61
+ })
62
+ }
63
+
64
+
65
+ }
66
+
@@ -16,7 +16,12 @@ export class ResourcesClient {
16
16
  })
17
17
  }
18
18
 
19
+ //** Deprecated **//
19
20
  createDocument(document) {
21
+ return this.create(document);
22
+ }
23
+
24
+ create(document) {
20
25
  return this.http.post(`/resources`, {
21
26
  type: document.type,
22
27
  location: document.location,
@@ -25,7 +30,7 @@ export class ResourcesClient {
25
30
  })
26
31
  }
27
32
 
28
- uploadFile({ location, file }) {
33
+ upload({ location = '/', file }) {
29
34
  return this.http.post(`/resources`, {
30
35
  type: file.type,
31
36
  location: location,
@@ -38,6 +43,18 @@ export class ResourcesClient {
38
43
  })
39
44
  }
40
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
+
41
58
  byId(resourceId) {
42
59
  return this.http.get(`/resources/${resourceId}`)
43
60
  }
@@ -46,15 +63,31 @@ export class ResourcesClient {
46
63
  return this.http.get(`/resources?location=${location}`)
47
64
  }
48
65
 
49
- byQuery(query) {
50
- return this.http.get(`/resources${!!query ? `?${query}` : ''}`)
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)
51
84
  }
52
85
 
53
86
  remove(resourceId) {
54
87
  return this.http.delete(`/resources/${resourceId}`)
55
88
  }
56
89
 
57
- updateResourceContent(resourceId, resourceContent) {
90
+ updateContent(resourceId, resourceContent) {
58
91
  return this.http.put(`/resources/${resourceId}/content`, resourceContent)
59
92
  }
60
93
 
package/src/sdk.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import { AuthClient } from './auth-client.js'
2
+ import { JobsClient } from './jobs-client.js'
2
3
  import { ApiTokensClient } from './api-tokens-client.js'
3
4
  import { ResourcesClient } from './resources-client.js'
5
+ import { UserClient } from './user-client.js'
4
6
  import { WorkspacesClient } from './workspaces-client.js'
5
7
  import { Http } from './http.js'
6
8
 
@@ -23,15 +25,21 @@ export class SDK {
23
25
  }
24
26
 
25
27
  const http = Http.of({
26
- baseUrl: this.config.apiUrl || 'https://api.ossy.se/api/v0',
27
- headers: { workspaceId: this.config.workspaceId }
28
+ baseUrl: this.config?.apiUrl || 'https://api.ossy.se/api/v0',
29
+ headers: {
30
+ workspaceId: this.config?.workspaceId,
31
+ Authorization: this.config?.apiKey
32
+ }
28
33
  })
29
34
 
30
35
  this.workspaceId = this.config.workspaceId
36
+ this.user = UserClient.of({ ...this.config, http })
31
37
  this.auth = AuthClient.of({ ...this.config, http })
38
+ this.workspaces = WorkspacesClient.of({ ...this.config, http })
32
39
  this.apiTokens = ApiTokensClient.of({ ...this.config, http })
33
40
  this.resources = ResourcesClient.of({ ...this.config, http })
34
- this.workspaces = WorkspacesClient.of({ ...this.config, http })
41
+ this.jobs = JobsClient.of({ ...this.config, http, resources: this.resources })
42
+
35
43
  }
36
44
 
37
45
  }
@@ -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,7 +5,16 @@ export class WorkspacesClient {
5
5
  }
6
6
 
7
7
  constructor(config) {
8
+ this.workspaceId = config?.workspaceId
8
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
+
9
18
  }
10
19
 
11
20
  getAll() {
@@ -22,35 +31,55 @@ export class WorkspacesClient {
22
31
 
23
32
  importResourceTempaltes(workspaceId, templates) {
24
33
  return this.http.post(
25
- `/workspaces/${workspaceId}/resource-templates`,
34
+ `/resource-templates`,
26
35
  templates
27
36
  )
28
37
  }
29
38
 
30
39
  getResourceTemplates(workspaceId) {
31
40
  return this.http.get(
32
- `/workspaces/${workspaceId}/resource-templates`
41
+ `/resource-templates`
33
42
  )
34
43
  }
35
44
 
36
45
  createApiToken(workspaceId, description) {
37
46
  return this.http.post(
38
- `/workspaces/${workspaceId}/tokens`,
47
+ `/tokens`,
39
48
  { workspaceId, description }
40
49
  )
41
50
  }
42
51
 
43
52
  getApiTokens(workspaceId) {
44
53
  return this.http.get(
45
- `/workspaces/${workspaceId}/tokens`
54
+ `/tokens`
46
55
  )
47
56
  }
48
57
 
49
58
  inviteUser(workspaceId, email) {
50
59
  return this.http.post(
51
- `/workspaces/${workspaceId}/invitations`,
60
+ `/invitations`,
52
61
  email
53
62
  )
54
63
  }
55
64
 
65
+ enableService(service) {
66
+ return this.http.post(
67
+ `/services/enable`,
68
+ service
69
+ )
70
+ }
71
+
72
+ disableService(service) {
73
+ return this.http.post(
74
+ `/services/disable`,
75
+ service
76
+ )
77
+ }
78
+
79
+ getUsers() {
80
+ return this.http.get(
81
+ `/users`
82
+ )
83
+ }
84
+
56
85
  }