@ossy/sdk 0.7.9 → 0.7.12

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,7 +1,38 @@
1
- import { SDKConfig, Action } from '@ossy/types';
1
+ import { Resource, Job, JobType, SDKConfig, Action } from '@ossy/types';
2
2
  export * from '@ossy/types';
3
3
  export { JobStatus, Jobs } from '@ossy/types';
4
4
 
5
+ interface ResourcesClient {
6
+ search: (payload: Record<string, unknown>) => Promise<Resource<Job>[]>;
7
+ create: (data: {
8
+ type: string;
9
+ location: string;
10
+ name: string;
11
+ content: {
12
+ resourceId: string;
13
+ status: string;
14
+ result: undefined;
15
+ };
16
+ }) => Promise<Resource<Job>>;
17
+ }
18
+ interface JobsClientConfig {
19
+ http?: unknown;
20
+ resources: ResourcesClient;
21
+ }
22
+ declare class JobsClient {
23
+ static location: string;
24
+ private http?;
25
+ private resources;
26
+ static of(config: JobsClientConfig): JobsClient;
27
+ constructor(config: JobsClientConfig);
28
+ get(_query?: string | Record<string, unknown>): Promise<Resource<Job>[]>;
29
+ getUnprocessed(): Promise<Resource<Job>[]>;
30
+ create({ type, resourceId }: {
31
+ type: JobType;
32
+ resourceId: string;
33
+ }): Promise<Resource<Job>>;
34
+ }
35
+
5
36
  declare class SDK {
6
37
  workspaceId?: string;
7
38
  authorization?: string;
@@ -88,9 +119,7 @@ declare class SDK {
88
119
  list: (query: ({
89
120
  location?: string;
90
121
  })) => Promise<any>;
91
- search: (_payload?: Required<{
92
- query: any;
93
- } | undefined>) => Promise<any>;
122
+ search: (_payload?: Required<Record<string, unknown> | undefined>) => Promise<any>;
94
123
  remove: (_payload?: Required<{
95
124
  id: string;
96
125
  } | undefined>) => Promise<any>;
@@ -128,6 +157,7 @@ declare class SDK {
128
157
  } | undefined>) => Promise<any>;
129
158
  signOff: (_payload?: Required<{} | undefined>) => Promise<any>;
130
159
  };
160
+ get jobs(): JobsClient;
131
161
  makeRequest: <T extends Action>(action: T) => (_payload?: Required<T["payload"]>) => Promise<any>;
132
162
  }
133
163
 
@@ -1 +1 @@
1
- const e={VisualContentDescriptors:"@ossy/jobs/visual-content-descriptors",ResizeCommonWeb:"@ossy/jobs/resize-common-web"},t={Queued:"queued",InProgress:"in progress",Success:"success",Failed:"failed"},s={id:"api-tokens.get-all",endpoint:"/users/me/tokens",method:"GET"},i={id:"api-tokens.create",endpoint:"/users/me/tokens",method:"POST"},n={id:"api-tokens.invalidate",endpoint:"/users/me/tokens/:id",method:"DELETE"},o={id:"workspaces.get-all",endpoint:"/workspaces",method:"GET"},r={id:"workspaces.get-current",endpoint:"/workspaces/current",method:"GET"},d={id:"workspaces.get",endpoint:"/workspaces/:id",method:"GET"},a={id:"workspaces.create",endpoint:"/workspaces",method:"POST"},h={id:"workspaces.import-resource-templates",endpoint:"/resource-templates",method:"POST"},u={id:"workspaces.get-resource-templates",endpoint:"/resource-templates",method:"GET"},c={id:"workspaces.create-api-token",endpoint:"/tokens",method:"POST"},p={id:"workspaces.get-api-tokens",endpoint:"/tokens",method:"GET"},m={id:"workspaces.invite-user",endpoint:"/invitations",method:"POST"},k={id:"workspaces.enable-service",endpoint:"/services/enable",method:"POST"},b={id:"workspaces.disable-service",endpoint:"/services/disable",method:"POST"},l={id:"workspaces.get-users",endpoint:"/users",method:"GET"},g={id:"user.get",endpoint:"/users/me",method:"GET"},T={id:"user.get-history",endpoint:"/users/me/history",method:"GET"},R={id:"user.update",endpoint:"/users/me",method:"PUT"},q={id:"resources.create-directory",endpoint:"/resources",method:"POST",payload:{type:"directory"}},y={id:"resources.create",endpoint:"/resources",method:"POST"},w={id:"resources.upload",endpoint:"/resources",method:"POST"},v={id:"resources.upload-named-version",endpoint:"/resources/:id/:name",method:"PUT"},P={id:"resources.get",endpoint:"/resources/:id",method:"GET"},E={id:"resources.list",endpoint:"/resources?:search",method:"GET"},U={id:"resources.search",endpoint:"/resources/search",method:"POST"},O={id:"resources.update-access",endpoint:"/resources/:id/access",method:"PUT"},f={id:"resources.remove",endpoint:"/resources/:id",method:"DELETE"},S={id:"resources.update-content",endpoint:"/resources/:id/content",method:"PUT"},G={id:"resources.move",endpoint:"/resources/:id/location",method:"PUT"},j={id:"resources.rename",endpoint:"/resources/:id/name",method:"PUT"},z={id:"auth.sign-up",endpoint:"/users/sign-up",method:"POST"},I={id:"auth.sign-in",endpoint:"/users/sign-in",method:"POST"},C={id:"auth.verify-sign-in",endpoint:"/users/verify-sign-in?token=:token",method:"GET"},A={id:"auth.verify-invitation",endpoint:"/workspaces/:workspaceId/invitations?token=:token",method:"GET"},D={id:"auth.get-authenticated-user",endpoint:"/users/me",method:"GET"},$={id:"auth.get-authenticated-user-history",endpoint:"/users/me/history",method:"GET"},J={id:"auth.get-user",endpoint:"/users/:id",method:"GET"},L={id:"auth.sign-off",endpoint:"/users/sign-off",method:"GET"};class N{static of(e){return new N(e)}constructor(e){this.baseUrl="https://api.ossy.se/api/v0",this.makeRequest=e=>t=>{let s={};(t||e.payload)&&(s=Object.assign(Object.assign({},e.payload||{}),t||{}));let i="apiUrl"in s?null==s?void 0:s.apiUrl:this.baseUrl,n="workspaceId"in s?s.workspaceId:this.workspaceId,o="authorization"in s?s.authorization:this.authorization,r=e.endpoint;if(s){const t=Object.keys(s);r=e.endpoint,r=t.reduce((e,t)=>e.replace(`:${t}`,`${s[t]}`),e.endpoint)}const d=`${i}${r}`,a={method:e.method,credentials:"include",headers:{"Content-Type":"application/json"}};return n&&(a.headers=Object.assign(Object.assign({},a.headers),{workspaceId:n})),o&&(a.headers=Object.assign(Object.assign({},a.headers),{Authorization:o})),"GET"!==a.method&&s&&(a.body=JSON.stringify(s)),fetch(d,a).then(e=>{const t=e.headers.get("Content-Type")||"",s=e.status;return 400===s?e.json().then(e=>Promise.reject(e.error)):[200,204].includes(s)?t.includes("application/json")?e.json():e:Promise.reject(e)})},this.updateConfig(e)}updateConfig(e){this.baseUrl=e.apiUrl||this.baseUrl,this.workspaceId=e.workspaceId||this.workspaceId,this.authorization=e.authorization||this.authorization}get apiTokens(){return{list:this.makeRequest(s).bind(this),create:this.makeRequest(i).bind(this),invalidate:this.makeRequest(n).bind(this)}}get workspaces(){return{current:this.makeRequest(r).bind(this),list:this.makeRequest(o).bind(this),get:this.makeRequest(d).bind(this),create:this.makeRequest(a).bind(this),importResourceTemplates:this.makeRequest(h).bind(this),getResourceTemplates:this.makeRequest(u).bind(this),createApiToken:this.makeRequest(c).bind(this),getApiTokens:this.makeRequest(p).bind(this),inviteUser:this.makeRequest(m).bind(this),enableService:this.makeRequest(k).bind(this),disableService:this.makeRequest(b).bind(this)}}get users(){return{list:this.makeRequest(l).bind(this)}}get currentUser(){return{get:this.makeRequest(g).bind(this),update:this.makeRequest(R).bind(this),history:this.makeRequest(T).bind(this)}}get resources(){return{createDirectory:this.makeRequest(q).bind(this),create:this.makeRequest(y).bind(this),access:this.makeRequest(O).bind(this),upload:({location:e="/",file:t})=>{const s={type:t.type,location:e,name:t.name,size:t.size};return this.makeRequest(w)(s).then(e=>fetch(e.content.uploadUrl,{method:"PUT",body:t}).then(()=>e))},uploadNamedVersion:({id:e,name:t,file:s})=>{const i={id:e,name:t,size:s.size};this.makeRequest(v)(i).then(e=>fetch(e.content.uploadUrl,{method:"PUT",body:s}).then(()=>e))},get:this.makeRequest(P).bind(this),list:e=>{const t=new URLSearchParams(Object.assign({},e)).toString();return this.makeRequest(E)({search:t})},search:this.makeRequest(U).bind(this),remove:this.makeRequest(f).bind(this),updateContent:this.makeRequest(S).bind(this),move:this.makeRequest(G).bind(this),rename:this.makeRequest(j).bind(this)}}get auth(){return{signUp:this.makeRequest(z).bind(this),signIn:this.makeRequest(I).bind(this),verifySignIn:this.makeRequest(C).bind(this),verifyInvitation:this.makeRequest(A).bind(this),getAuthenticatedUser:this.makeRequest(D).bind(this),getAuthenticatedUserHistory:this.makeRequest($).bind(this),getUser:this.makeRequest(J).bind(this),signOff:this.makeRequest(L).bind(this)}}}export{t as JobStatus,e as Jobs,N as SDK};
1
+ const e={VisualContentDescriptors:"@ossy/jobs/visual-content-descriptors",ResizeCommonWeb:"@ossy/jobs/resize-common-web"},t={Queued:"queued",InProgress:"in progress",Success:"success",Failed:"failed"};class s{static of(e){return new s(e)}constructor(e){this.http=null==e?void 0:e.http,this.resources=e.resources}get(e={}){const t="string"==typeof e?{id:e}:e;return t.location=s.location,this.resources.search({query:t})}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:i,resourceId:o}){if(!Object.values(e).includes(i))throw new Error(`Job type ${i} does not exist`);if(!o)throw new Error("Resource ID is required");return this.resources.create({type:i,location:s.location,name:`[${t.Queued}] ${o}`,content:{resourceId:o,status:t.Queued,result:void 0}})}}s.location="/@ossy/jobs/";const i={id:"api-tokens.get-all",endpoint:"/users/me/tokens",method:"GET"},o={id:"api-tokens.create",endpoint:"/users/me/tokens",method:"POST"},n={id:"api-tokens.invalidate",endpoint:"/users/me/tokens/:id",method:"DELETE"},r={id:"workspaces.get-all",endpoint:"/workspaces",method:"GET"},d={id:"workspaces.get-current",endpoint:"/workspaces/current",method:"GET"},a={id:"workspaces.get",endpoint:"/workspaces/:id",method:"GET"},u={id:"workspaces.create",endpoint:"/workspaces",method:"POST"},h={id:"workspaces.import-resource-templates",endpoint:"/resource-templates",method:"POST"},c={id:"workspaces.get-resource-templates",endpoint:"/resource-templates",method:"GET"},p={id:"workspaces.create-api-token",endpoint:"/tokens",method:"POST"},m={id:"workspaces.get-api-tokens",endpoint:"/tokens",method:"GET"},k={id:"workspaces.invite-user",endpoint:"/invitations",method:"POST"},l={id:"workspaces.enable-service",endpoint:"/services/enable",method:"POST"},b={id:"workspaces.disable-service",endpoint:"/services/disable",method:"POST"},g={id:"workspaces.get-users",endpoint:"/users",method:"GET"},T={id:"user.get",endpoint:"/users/me",method:"GET"},R={id:"user.get-history",endpoint:"/users/me/history",method:"GET"},q={id:"user.update",endpoint:"/users/me",method:"PUT"},y={id:"resources.create-directory",endpoint:"/resources",method:"POST",payload:{type:"directory"}},w={id:"resources.create",endpoint:"/resources",method:"POST"},v={id:"resources.upload",endpoint:"/resources",method:"POST"},f={id:"resources.upload-named-version",endpoint:"/resources/:id/:name",method:"PUT"},E={id:"resources.get",endpoint:"/resources/:id",method:"GET"},P={id:"resources.list",endpoint:"/resources?:search",method:"GET"},U={id:"resources.search",endpoint:"/resources/search",method:"POST"},O={id:"resources.update-access",endpoint:"/resources/:id/access",method:"PUT"},j={id:"resources.remove",endpoint:"/resources/:id",method:"DELETE"},S={id:"resources.update-content",endpoint:"/resources/:id/content",method:"PUT"},G={id:"resources.move",endpoint:"/resources/:id/location",method:"PUT"},I={id:"resources.rename",endpoint:"/resources/:id/name",method:"PUT"},z={id:"auth.sign-up",endpoint:"/users/sign-up",method:"POST"},$={id:"auth.sign-in",endpoint:"/users/sign-in",method:"POST"},x={id:"auth.verify-sign-in",endpoint:"/users/verify-sign-in?token=:token",method:"GET"},C={id:"auth.verify-invitation",endpoint:"/workspaces/:workspaceId/invitations?token=:token",method:"GET"},D={id:"auth.get-authenticated-user",endpoint:"/users/me",method:"GET"},A={id:"auth.get-authenticated-user-history",endpoint:"/users/me/history",method:"GET"},J={id:"auth.get-user",endpoint:"/users/:id",method:"GET"},L={id:"auth.sign-off",endpoint:"/users/sign-off",method:"GET"};class Q{static of(e){return new Q(e)}constructor(e){this.baseUrl="https://api.ossy.se/api/v0",this.makeRequest=e=>t=>{let s={};(t||e.payload)&&(s=Object.assign(Object.assign({},e.payload||{}),t||{}));let i="apiUrl"in s?null==s?void 0:s.apiUrl:this.baseUrl,o="workspaceId"in s?s.workspaceId:this.workspaceId,n="authorization"in s?s.authorization:this.authorization,r=e.endpoint;if(s){const t=Object.keys(s);r=e.endpoint,r=t.reduce((e,t)=>e.replace(`:${t}`,`${s[t]}`),e.endpoint)}const d=`${i}${r}`,a={method:e.method,credentials:"include",headers:{"Content-Type":"application/json"}};return o&&(a.headers=Object.assign(Object.assign({},a.headers),{workspaceId:o})),n&&(a.headers=Object.assign(Object.assign({},a.headers),{Authorization:n})),"GET"!==a.method&&s&&(a.body=JSON.stringify(s)),fetch(d,a).then(e=>{const t=e.headers.get("Content-Type")||"",s=e.status;return 400===s?e.json().then(e=>Promise.reject(e.error)):[200,204].includes(s)?t.includes("application/json")?e.json():e:Promise.reject(e)})},this.updateConfig(e)}updateConfig(e){this.baseUrl=e.apiUrl||this.baseUrl,this.workspaceId=e.workspaceId||this.workspaceId,this.authorization=e.authorization||this.authorization}get apiTokens(){return{list:this.makeRequest(i).bind(this),create:this.makeRequest(o).bind(this),invalidate:this.makeRequest(n).bind(this)}}get workspaces(){return{current:this.makeRequest(d).bind(this),list:this.makeRequest(r).bind(this),get:this.makeRequest(a).bind(this),create:this.makeRequest(u).bind(this),importResourceTemplates:this.makeRequest(h).bind(this),getResourceTemplates:this.makeRequest(c).bind(this),createApiToken:this.makeRequest(p).bind(this),getApiTokens:this.makeRequest(m).bind(this),inviteUser:this.makeRequest(k).bind(this),enableService:this.makeRequest(l).bind(this),disableService:this.makeRequest(b).bind(this)}}get users(){return{list:this.makeRequest(g).bind(this)}}get currentUser(){return{get:this.makeRequest(T).bind(this),update:this.makeRequest(q).bind(this),history:this.makeRequest(R).bind(this)}}get resources(){return{createDirectory:this.makeRequest(y).bind(this),create:this.makeRequest(w).bind(this),access:this.makeRequest(O).bind(this),upload:({location:e="/",file:t})=>{const s={type:t.type,location:e,name:t.name,size:t.size};return this.makeRequest(v)(s).then(e=>fetch(e.content.uploadUrl,{method:"PUT",body:t}).then(()=>e))},uploadNamedVersion:({id:e,name:t,file:s})=>{const i={id:e,name:t,size:s.size};this.makeRequest(f)(i).then(e=>fetch(e.content.uploadUrl,{method:"PUT",body:s}).then(()=>e))},get:this.makeRequest(E).bind(this),list:e=>{const t=new URLSearchParams(Object.assign({},e)).toString();return this.makeRequest(P)({search:t})},search:this.makeRequest(U).bind(this),remove:this.makeRequest(j).bind(this),updateContent:this.makeRequest(S).bind(this),move:this.makeRequest(G).bind(this),rename:this.makeRequest(I).bind(this)}}get auth(){return{signUp:this.makeRequest(z).bind(this),signIn:this.makeRequest($).bind(this),verifySignIn:this.makeRequest(x).bind(this),verifyInvitation:this.makeRequest(C).bind(this),getAuthenticatedUser:this.makeRequest(D).bind(this),getAuthenticatedUserHistory:this.makeRequest(A).bind(this),getUser:this.makeRequest(J).bind(this),signOff:this.makeRequest(L).bind(this)}}get jobs(){return s.of({resources:this.resources})}}export{t as JobStatus,e as Jobs,Q as SDK};
@@ -68,9 +68,7 @@ export declare const ResourcesGet: Action<{
68
68
  export declare const ResourcesList: Action<{
69
69
  search?: string;
70
70
  }>;
71
- export declare const ResourcesSearch: Action<{
72
- query: any;
73
- }>;
71
+ export declare const ResourcesSearch: Action<Record<string, unknown>>;
74
72
  export declare const ResourceUpdateAccess: Action<{
75
73
  id: string;
76
74
  access: 'restricted' | 'public';
@@ -1,16 +1,32 @@
1
- export class JobsClient {
1
+ import { Jobs, JobStatus, JobType, Resource, Job } from '@ossy/types';
2
+ export { Jobs, JobStatus };
3
+ interface ResourcesClient {
4
+ search: (payload: Record<string, unknown>) => Promise<Resource<Job>[]>;
5
+ create: (data: {
6
+ type: string;
7
+ location: string;
8
+ name: string;
9
+ content: {
10
+ resourceId: string;
11
+ status: string;
12
+ result: undefined;
13
+ };
14
+ }) => Promise<Resource<Job>>;
15
+ }
16
+ interface JobsClientConfig {
17
+ http?: unknown;
18
+ resources: ResourcesClient;
19
+ }
20
+ export declare class JobsClient {
2
21
  static location: string;
3
- static of(config: any): JobsClient;
4
- constructor(config: any);
5
- http: any;
6
- resources: any;
7
- get(_query?: {}): any;
8
- getUnprocessed(): any;
22
+ private http?;
23
+ private resources;
24
+ static of(config: JobsClientConfig): JobsClient;
25
+ constructor(config: JobsClientConfig);
26
+ get(_query?: string | Record<string, unknown>): Promise<Resource<Job>[]>;
27
+ getUnprocessed(): Promise<Resource<Job>[]>;
9
28
  create({ type, resourceId }: {
10
- type: any;
11
- resourceId: any;
12
- }): any;
29
+ type: JobType;
30
+ resourceId: string;
31
+ }): Promise<Resource<Job>>;
13
32
  }
14
- import { Jobs } from '@ossy/types';
15
- import { JobStatus } from '@ossy/types';
16
- export { Jobs, JobStatus };
@@ -1,5 +1,6 @@
1
1
  import { Action } from './Actions';
2
2
  import { SDKConfig } from './config';
3
+ import { JobsClient } from './jobs-client';
3
4
  export declare class SDK {
4
5
  workspaceId?: string;
5
6
  authorization?: string;
@@ -86,9 +87,7 @@ export declare class SDK {
86
87
  list: (query: ({
87
88
  location?: string;
88
89
  })) => Promise<any>;
89
- search: (_payload?: Required<{
90
- query: any;
91
- } | undefined>) => Promise<any>;
90
+ search: (_payload?: Required<Record<string, unknown> | undefined>) => Promise<any>;
92
91
  remove: (_payload?: Required<{
93
92
  id: string;
94
93
  } | undefined>) => Promise<any>;
@@ -126,5 +125,6 @@ export declare class SDK {
126
125
  } | undefined>) => Promise<any>;
127
126
  signOff: (_payload?: Required<{} | undefined>) => Promise<any>;
128
127
  };
128
+ get jobs(): JobsClient;
129
129
  makeRequest: <T extends Action>(action: T) => (_payload?: Required<T["payload"]>) => Promise<any>;
130
130
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ossy/sdk",
3
3
  "description": "Sofware Development Kit for interacting with our services",
4
- "version": "0.7.9",
4
+ "version": "0.7.12",
5
5
  "url": "git://github.com/ossy-se/packages/sdk",
6
6
  "source": "src/public.index.ts",
7
7
  "main": "build/public.index.js",
@@ -21,7 +21,7 @@
21
21
  },
22
22
  "license": "MIT",
23
23
  "dependencies": {
24
- "@ossy/types": "^0.0.8"
24
+ "@ossy/types": "^0.0.11"
25
25
  },
26
26
  "scripts": {
27
27
  "start": "",
@@ -36,5 +36,5 @@
36
36
  "/build",
37
37
  "README.md"
38
38
  ],
39
- "gitHead": "c4fe33a8cd5f590321c5f008d7407da95f094820"
39
+ "gitHead": "3bb7294899db2f2c76389eeec7986fa32f46b3d5"
40
40
  }