@ossy/sdk 0.0.7-alpha → 0.0.9-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.
@@ -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"},s={Queued:"queued",Success:"success",Failed:"failed"};class r{static of(t){return new r(t)}constructor(t){this.http=t?.http,this.resources=t?.resources}get({type:t}){if(!Object.values(e).includes(t))throw new Error(`Job type ${t} does not exist`);return this.resources.byLocation(t)}create({type:t,resourceId:r}){if(!Object.values(e).includes(t))throw new Error(`Job type ${t} does not exist`);if(!r)throw new Error("Resource ID is required");return this.resources.create({type:t,location:t,name:`[${s.Queued}] ${r}`,content:{resourceId:r,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})}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}`)}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",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 +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"},s={Queued:"queued",Success:"success",Failed:"failed"};class r{static of(t){return new r(t)}constructor(t){this.http=t?.http,this.resources=t?.resources}get({type:t}){if(!Object.values(e).includes(t))throw new Error(`Job type ${t} does not exist`);return this.resources.byLocation(t)}create({type:t,resourceId:r}){if(!Object.values(e).includes(t))throw new Error(`Job type ${t} does not exist`);if(!r)throw new Error("Resource ID is required");return this.resources.create({type:t,location:t,name:`[${s.Queued}] ${r}`,content:{resourceId:r,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})}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}`)}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})}}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",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};
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@ossy/sdk",
3
3
  "description": "Sofware Development Kit for interactive with our services",
4
- "version": "0.0.7-alpha",
4
+ "version": "0.0.9-alpha",
5
5
  "url": "git://github.com/ossy-se/ossy.git",
6
6
  "source": "src/index.js",
7
+ "type": "module",
7
8
  "main": "build/index.cjs.js",
8
9
  "module": "build/index.esm.js",
9
10
  "author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
@@ -1,5 +1,6 @@
1
1
  export const Jobs = {
2
- VisualContentDescriptors: '@ossy/jobs/visual-content-descriptors'
2
+ VisualContentDescriptors: '@ossy/jobs/visual-content-descriptors',
3
+ ResizeCommonWeb: '@ossy/jobs/resize-common-web',
3
4
  }
4
5
 
5
6
  export const JobStatus = {
@@ -9,6 +10,7 @@ export const JobStatus = {
9
10
  }
10
11
 
11
12
  export class JobsClient {
13
+ static location = '@ossy/jobs'
12
14
 
13
15
  static of(config) {
14
16
  return new JobsClient(config)
@@ -19,10 +21,10 @@ export class JobsClient {
19
21
  this.resources = config?.resources
20
22
  }
21
23
 
22
- get({ type }) {
23
- const jobTypeExists = Object.values(Jobs).includes(type)
24
- if (!jobTypeExists) throw new Error(`Job type ${type} does not exist`)
25
- return this.resources.byLocation(type)
24
+ get(_query = {}) {
25
+ const query = typeof _query === 'string' ? { id: _query } : _query
26
+ query.location = JobsClient.location
27
+ return this.resources.get(query)
26
28
  }
27
29
 
28
30
  create({ type, resourceId }) {
@@ -31,7 +33,7 @@ export class JobsClient {
31
33
  if (!resourceId) throw new Error(`Resource ID is required`)
32
34
  return this.resources.create({
33
35
  type,
34
- location: type,
36
+ location: JobsClient.location,
35
37
  name: `[${JobStatus.Queued}] ${resourceId}`,
36
38
  content: {
37
39
  resourceId,
@@ -0,0 +1,14 @@
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()
@@ -30,7 +30,7 @@ export class ResourcesClient {
30
30
  })
31
31
  }
32
32
 
33
- uploadFile({ location, file }) {
33
+ upload({ location = '/', file }) {
34
34
  return this.http.post(`/resources`, {
35
35
  type: file.type,
36
36
  location: location,
@@ -43,6 +43,18 @@ export class ResourcesClient {
43
43
  })
44
44
  }
45
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
+
46
58
  byId(resourceId) {
47
59
  return this.http.get(`/resources/${resourceId}`)
48
60
  }
@@ -51,8 +63,14 @@ export class ResourcesClient {
51
63
  return this.http.get(`/resources?location=${location}`)
52
64
  }
53
65
 
54
- byQuery(query) {
55
- 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}`)
56
74
  }
57
75
 
58
76
  remove(resourceId) {