@api-client/core 0.5.2 → 0.5.5
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/build/browser.d.ts +2 -1
- package/build/browser.js +2 -1
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +2 -1
- package/build/index.js +2 -1
- package/build/index.js.map +1 -1
- package/build/src/models/Backend.d.ts +7 -9
- package/build/src/models/HttpHistory.d.ts +2 -2
- package/build/src/models/Project.d.ts +41 -0
- package/build/src/models/Project.js +94 -0
- package/build/src/models/Project.js.map +1 -0
- package/build/src/models/RevisionInfo.d.ts +5 -0
- package/build/src/models/RevisionInfo.js.map +1 -1
- package/build/src/models/SerializableError.d.ts +1 -0
- package/build/src/models/SerializableError.js.map +1 -1
- package/build/src/models/Thing.js +1 -1
- package/build/src/models/Thing.js.map +1 -1
- package/build/src/models/Workspace.d.ts +0 -17
- package/build/src/models/Workspace.js +3 -19
- package/build/src/models/Workspace.js.map +1 -1
- package/build/src/models/store/Deletion.d.ts +24 -0
- package/build/src/models/store/Deletion.js +2 -0
- package/build/src/models/store/Deletion.js.map +1 -0
- package/build/src/models/store/File.d.ts +75 -12
- package/build/src/models/store/File.js +120 -19
- package/build/src/models/store/File.js.map +1 -1
- package/build/src/models/store/Modification.d.ts +24 -0
- package/build/src/models/store/Modification.js +2 -0
- package/build/src/models/store/Modification.js.map +1 -0
- package/build/src/runtime/store/Errors.d.ts +50 -0
- package/build/src/runtime/store/Errors.js +63 -0
- package/build/src/runtime/store/Errors.js.map +1 -0
- package/build/src/runtime/store/FilesSdk.d.ts +94 -0
- package/build/src/runtime/store/FilesSdk.js +247 -0
- package/build/src/runtime/store/FilesSdk.js.map +1 -0
- package/build/src/runtime/store/HistorySdk.d.ts +14 -7
- package/build/src/runtime/store/HistorySdk.js +34 -12
- package/build/src/runtime/store/HistorySdk.js.map +1 -1
- package/build/src/runtime/store/RouteBuilder.d.ts +9 -17
- package/build/src/runtime/store/RouteBuilder.js +14 -26
- package/build/src/runtime/store/RouteBuilder.js.map +1 -1
- package/build/src/runtime/store/Sdk.d.ts +6 -7
- package/build/src/runtime/store/Sdk.js +6 -7
- package/build/src/runtime/store/Sdk.js.map +1 -1
- package/build/src/runtime/store/SdkBase.d.ts +16 -6
- package/build/src/runtime/store/SdkBase.js +54 -4
- package/build/src/runtime/store/SdkBase.js.map +1 -1
- package/build/src/runtime/store/SharedSdk.d.ts +8 -2
- package/build/src/runtime/store/SharedSdk.js +22 -8
- package/build/src/runtime/store/SharedSdk.js.map +1 -1
- package/build/src/runtime/store/StoreSdkNode.d.ts +1 -1
- package/build/src/runtime/store/StoreSdkWeb.d.ts +1 -1
- package/build/src/runtime/store/UsersSdk.d.ts +10 -4
- package/build/src/runtime/store/UsersSdk.js +12 -6
- package/build/src/runtime/store/UsersSdk.js.map +1 -1
- package/package.json +2 -2
- package/src/models/Backend.ts +7 -9
- package/src/models/HttpHistory.ts +2 -2
- package/src/models/Project.ts +110 -0
- package/src/models/RevisionInfo.ts +6 -0
- package/src/models/SerializableError.ts +1 -0
- package/src/models/Thing.ts +1 -1
- package/src/models/Workspace.ts +4 -29
- package/src/models/store/Deletion.ts +24 -0
- package/src/models/store/File.ts +146 -26
- package/src/models/store/Modification.ts +24 -0
- package/src/runtime/store/Errors.ts +100 -0
- package/src/runtime/store/FilesSdk.ts +302 -0
- package/src/runtime/store/HistorySdk.ts +42 -17
- package/src/runtime/store/RouteBuilder.ts +14 -28
- package/src/runtime/store/Sdk.ts +7 -7
- package/src/runtime/store/SdkBase.ts +63 -9
- package/src/runtime/store/SharedSdk.ts +27 -10
- package/src/runtime/store/StoreSdkNode.ts +1 -1
- package/src/runtime/store/StoreSdkWeb.ts +1 -1
- package/src/runtime/store/UsersSdk.ts +14 -8
- package/build/src/models/HttpProjectListItem.d.ts +0 -23
- package/build/src/models/HttpProjectListItem.js +0 -2
- package/build/src/models/HttpProjectListItem.js.map +0 -1
- package/build/src/runtime/store/ProjectsSdk.d.ts +0 -43
- package/build/src/runtime/store/ProjectsSdk.js +0 -144
- package/build/src/runtime/store/ProjectsSdk.js.map +0 -1
- package/build/src/runtime/store/SpacesSdk.d.ts +0 -62
- package/build/src/runtime/store/SpacesSdk.js +0 -194
- package/build/src/runtime/store/SpacesSdk.js.map +0 -1
- package/src/models/HttpProjectListItem.ts +0 -23
- package/src/runtime/store/ProjectsSdk.ts +0 -147
- package/src/runtime/store/SpacesSdk.ts +0 -209
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION } from './SdkBase.js';
|
|
1
|
+
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, E_RESPONSE_LOCATION, ISdkRequestOptions } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
|
-
import { IListResponse, HistoryListOptions } from '../../models/Backend.js';
|
|
3
|
+
import { IListResponse, HistoryListOptions, IHistoryRequestListOptions } from '../../models/Backend.js';
|
|
4
4
|
import { IHttpHistory, IHttpHistoryBulkAdd, Kind as HttpHistoryKind } from '../../models/HttpHistory.js';
|
|
5
5
|
|
|
6
6
|
export class HistorySdk extends SdkBase {
|
|
@@ -14,10 +14,11 @@ export class HistorySdk extends SdkBase {
|
|
|
14
14
|
* Note, history objects cannot be updated. They can only be created or deleted.
|
|
15
15
|
*
|
|
16
16
|
* @param history The history to create
|
|
17
|
+
* @param request Optional request options.
|
|
17
18
|
* @returns The key of the created history.
|
|
18
19
|
*/
|
|
19
|
-
async create(history: IHttpHistory): Promise<string> {
|
|
20
|
-
const
|
|
20
|
+
async create(history: IHttpHistory, request: ISdkRequestOptions = {}): Promise<string> {
|
|
21
|
+
const token = request.token || this.sdk.token;
|
|
21
22
|
const url = this.sdk.getUrl(RouteBuilder.history());
|
|
22
23
|
const body = JSON.stringify(history);
|
|
23
24
|
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
@@ -39,9 +40,10 @@ export class HistorySdk extends SdkBase {
|
|
|
39
40
|
* Creates a multiple history objects in a batch operation.
|
|
40
41
|
*
|
|
41
42
|
* @param info The bulk create info object.
|
|
43
|
+
* @param request Optional request options.
|
|
42
44
|
*/
|
|
43
|
-
async createBulk(info: IHttpHistoryBulkAdd): Promise<string[]> {
|
|
44
|
-
const
|
|
45
|
+
async createBulk(info: IHttpHistoryBulkAdd, request: ISdkRequestOptions = {}): Promise<string[]> {
|
|
46
|
+
const token = request.token || this.sdk.token;
|
|
45
47
|
const url = this.sdk.getUrl(RouteBuilder.historyBatchCreate());
|
|
46
48
|
const body = JSON.stringify(info);
|
|
47
49
|
const result = await this.sdk.http.post(url.toString(), { token, body });
|
|
@@ -56,7 +58,7 @@ export class HistorySdk extends SdkBase {
|
|
|
56
58
|
}
|
|
57
59
|
let data: string[];
|
|
58
60
|
try {
|
|
59
|
-
data = JSON.parse(result.body);
|
|
61
|
+
data = JSON.parse(result.body).data;
|
|
60
62
|
} catch (e) {
|
|
61
63
|
throw new Error(`${E_PREFIX}${E_INVALID_JSON}.`);
|
|
62
64
|
}
|
|
@@ -67,11 +69,12 @@ export class HistorySdk extends SdkBase {
|
|
|
67
69
|
* Lists the history.
|
|
68
70
|
*
|
|
69
71
|
* @param options Optional query options.
|
|
72
|
+
* @param request Optional request options.
|
|
70
73
|
*/
|
|
71
|
-
async list(options: HistoryListOptions): Promise<IListResponse
|
|
72
|
-
const
|
|
74
|
+
async list(options: HistoryListOptions, request: ISdkRequestOptions = {}): Promise<IListResponse<IHttpHistory>> {
|
|
75
|
+
const token = request.token || this.sdk.token;
|
|
73
76
|
const url = this.sdk.getUrl(RouteBuilder.history());
|
|
74
|
-
this.
|
|
77
|
+
this.appendHistoryListParameters(url, options);
|
|
75
78
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
76
79
|
this.inspectCommonStatusCodes(result.status);
|
|
77
80
|
const E_PREFIX = 'Unable to list history. ';
|
|
@@ -82,7 +85,7 @@ export class HistorySdk extends SdkBase {
|
|
|
82
85
|
if (!result.body) {
|
|
83
86
|
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
84
87
|
}
|
|
85
|
-
let data: IListResponse
|
|
88
|
+
let data: IListResponse<IHttpHistory>;
|
|
86
89
|
try {
|
|
87
90
|
data = JSON.parse(result.body);
|
|
88
91
|
} catch (e) {
|
|
@@ -94,24 +97,45 @@ export class HistorySdk extends SdkBase {
|
|
|
94
97
|
return data;
|
|
95
98
|
}
|
|
96
99
|
|
|
100
|
+
appendHistoryListParameters(url: URL, options: HistoryListOptions): void {
|
|
101
|
+
this.sdk.appendListOptions(url, options);
|
|
102
|
+
const { searchParams } = url;
|
|
103
|
+
if (options.type) {
|
|
104
|
+
searchParams.set('type', options.type);
|
|
105
|
+
}
|
|
106
|
+
const projectOptions = options as IHistoryRequestListOptions;
|
|
107
|
+
if (projectOptions.id) {
|
|
108
|
+
searchParams.set('id', projectOptions.id);
|
|
109
|
+
}
|
|
110
|
+
if (projectOptions.user) {
|
|
111
|
+
searchParams.set('user', 'true');
|
|
112
|
+
}
|
|
113
|
+
if (projectOptions.project) {
|
|
114
|
+
searchParams.set('project', projectOptions.project);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
97
118
|
/**
|
|
98
119
|
* Deletes a history object form the store.
|
|
99
120
|
*
|
|
100
121
|
* @param key The key returned by the store when created the history. Also available via the `key` property on the history object.
|
|
122
|
+
* @param request Optional request options.
|
|
101
123
|
*/
|
|
102
|
-
delete(key: string): Promise<void>;
|
|
124
|
+
delete(key: string, request?: ISdkRequestOptions): Promise<void>;
|
|
103
125
|
/**
|
|
104
126
|
* Deletes a list of history objects in a batch operation.
|
|
105
127
|
*
|
|
106
128
|
* @param keys The keys returned by the store when created the history. Also available via the `key` property on the history object.
|
|
129
|
+
* @param request Optional request options.
|
|
107
130
|
*/
|
|
108
|
-
delete(keys: string[]): Promise<void>;
|
|
131
|
+
delete(keys: string[], request?: ISdkRequestOptions): Promise<void>;
|
|
109
132
|
/**
|
|
110
133
|
* Deletes a history or a list of history objects from the store.
|
|
111
134
|
* @param key A key or a list of keys.
|
|
135
|
+
* @param request Optional request options.
|
|
112
136
|
*/
|
|
113
|
-
async delete(key: string | string[]): Promise<void> {
|
|
114
|
-
const
|
|
137
|
+
async delete(key: string | string[], request: ISdkRequestOptions = {}): Promise<void> {
|
|
138
|
+
const token = request.token || this.sdk.token;
|
|
115
139
|
const isArray = Array.isArray(key);
|
|
116
140
|
const path = isArray ? RouteBuilder.historyBatchDelete() : RouteBuilder.historyItem(key);
|
|
117
141
|
const url = this.sdk.getUrl(path);
|
|
@@ -128,10 +152,11 @@ export class HistorySdk extends SdkBase {
|
|
|
128
152
|
/**
|
|
129
153
|
* Reads a history definition from the store.
|
|
130
154
|
* @param key The history key
|
|
155
|
+
* @param request Optional request options.
|
|
131
156
|
* @returns The history object
|
|
132
157
|
*/
|
|
133
|
-
async read(key: string): Promise<IHttpHistory> {
|
|
134
|
-
const
|
|
158
|
+
async read(key: string, request: ISdkRequestOptions = {}): Promise<IHttpHistory> {
|
|
159
|
+
const token = request.token || this.sdk.token;
|
|
135
160
|
const url = this.sdk.getUrl(RouteBuilder.historyItem(key));
|
|
136
161
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
137
162
|
this.inspectCommonStatusCodes(result.status);
|
|
@@ -3,45 +3,31 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export class RouteBuilder {
|
|
5
5
|
/**
|
|
6
|
-
* @returns The path to the /
|
|
6
|
+
* @returns The path to the /files route.
|
|
7
7
|
*/
|
|
8
|
-
static
|
|
9
|
-
return '/
|
|
8
|
+
static files(): string {
|
|
9
|
+
return '/files';
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
* @returns The path to the /
|
|
13
|
+
* @returns The path to the /files/[id] route.
|
|
14
14
|
*/
|
|
15
|
-
static
|
|
16
|
-
return `/
|
|
15
|
+
static file(key: string): string {
|
|
16
|
+
return `/files/${key}`;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* @returns The path to the /
|
|
20
|
+
* @returns The path to the /files/[id]/users route.
|
|
21
21
|
*/
|
|
22
|
-
static
|
|
23
|
-
return `/
|
|
22
|
+
static fileUsers(key: string): string {
|
|
23
|
+
return `/files/${key}/users`;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* @returns The path to the /
|
|
27
|
+
* @returns The path to the /file/[id]/revisions route.
|
|
28
28
|
*/
|
|
29
|
-
static
|
|
30
|
-
return `/
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @returns The path to the /spaces/[id]/projects/[id] route.
|
|
35
|
-
*/
|
|
36
|
-
static spaceProject(space: string, project: string): string {
|
|
37
|
-
return `/spaces/${space}/projects/${project}`;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @returns The path to the /spaces/[id]/projects/[id]/revisions route.
|
|
42
|
-
*/
|
|
43
|
-
static projectRevisions(space: string, project: string): string {
|
|
44
|
-
return `/spaces/${space}/projects/${project}/revisions`;
|
|
29
|
+
static fileRevisions(file: string): string {
|
|
30
|
+
return `/file/${file}/revisions`;
|
|
45
31
|
}
|
|
46
32
|
|
|
47
33
|
/**
|
|
@@ -87,7 +73,7 @@ export class RouteBuilder {
|
|
|
87
73
|
return `/history/${key}`;
|
|
88
74
|
}
|
|
89
75
|
|
|
90
|
-
static
|
|
91
|
-
return '/shared
|
|
76
|
+
static shared(): string {
|
|
77
|
+
return '/shared';
|
|
92
78
|
}
|
|
93
79
|
}
|
package/src/runtime/store/Sdk.ts
CHANGED
|
@@ -3,8 +3,7 @@ import { Http } from './Http.js';
|
|
|
3
3
|
import { WsClient } from './WsClient.js';
|
|
4
4
|
import { AuthSdk } from './AuthSdk.js';
|
|
5
5
|
import { BackendSdk } from './BackendSdk.js';
|
|
6
|
-
import {
|
|
7
|
-
import { ProjectsSdk } from './ProjectsSdk.js';
|
|
6
|
+
import { FilesSdk } from './FilesSdk.js';
|
|
8
7
|
import { UsersSdk } from './UsersSdk.js';
|
|
9
8
|
import { HistorySdk } from './HistorySdk.js';
|
|
10
9
|
import { SharedSdk } from './SharedSdk.js';
|
|
@@ -30,11 +29,7 @@ export abstract class Sdk {
|
|
|
30
29
|
/**
|
|
31
30
|
* The user spaces features.
|
|
32
31
|
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* The user projects features.
|
|
36
|
-
*/
|
|
37
|
-
project = new ProjectsSdk(this);
|
|
32
|
+
file = new FilesSdk(this);
|
|
38
33
|
/**
|
|
39
34
|
* Reads user information.
|
|
40
35
|
*/
|
|
@@ -56,6 +51,11 @@ export abstract class Sdk {
|
|
|
56
51
|
*/
|
|
57
52
|
shared = new SharedSdk(this);
|
|
58
53
|
|
|
54
|
+
/**
|
|
55
|
+
* When set it limits log output to minimum.
|
|
56
|
+
*/
|
|
57
|
+
silent = false;
|
|
58
|
+
|
|
59
59
|
|
|
60
60
|
[baseUriSymbol] = '';
|
|
61
61
|
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { Headers } from '../../lib/headers/Headers.js';
|
|
2
2
|
import { Sdk } from './Sdk.js';
|
|
3
|
+
import { SdkError, IApiError } from './Errors.js';
|
|
3
4
|
|
|
4
|
-
export interface
|
|
5
|
-
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
6
|
-
headers?: Record<string, string>,
|
|
7
|
-
body?: string | Buffer;
|
|
5
|
+
export interface ISdkRequestOptions {
|
|
8
6
|
/**
|
|
9
|
-
*
|
|
7
|
+
* Uses the provided token for authentication.
|
|
10
8
|
*/
|
|
11
9
|
token?: string;
|
|
12
10
|
}
|
|
13
11
|
|
|
12
|
+
export interface IStoreRequestOptions extends ISdkRequestOptions {
|
|
13
|
+
method?: 'GET' | 'POST' | 'PATCH' | 'DELETE';
|
|
14
|
+
headers?: Record<string, string>,
|
|
15
|
+
body?: string | Buffer;
|
|
16
|
+
}
|
|
17
|
+
|
|
14
18
|
export interface IStoreResponse {
|
|
15
19
|
status: number;
|
|
16
20
|
headers: Headers;
|
|
@@ -42,6 +46,9 @@ export class SdkBase {
|
|
|
42
46
|
constructor(public sdk: Sdk) {}
|
|
43
47
|
|
|
44
48
|
protected logInvalidResponse(response: IStoreResponse): void {
|
|
49
|
+
if (this.sdk.silent) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
45
52
|
if (response.body) {
|
|
46
53
|
try {
|
|
47
54
|
const data = JSON.parse(response.body);
|
|
@@ -58,15 +65,62 @@ export class SdkBase {
|
|
|
58
65
|
* Throws unified message for a common error status codes.
|
|
59
66
|
* It handles 404, 403, and 401 status codes.
|
|
60
67
|
*/
|
|
61
|
-
protected inspectCommonStatusCodes(status: number): void {
|
|
68
|
+
protected inspectCommonStatusCodes(status: number, body?: string): void {
|
|
62
69
|
if (status === 404) {
|
|
63
|
-
|
|
70
|
+
let e = this.createGenericSdkError(body)
|
|
71
|
+
if (!e) {
|
|
72
|
+
e = new SdkError(`Not found.`, 400);
|
|
73
|
+
e.response = body;
|
|
74
|
+
}
|
|
75
|
+
throw e;
|
|
64
76
|
}
|
|
65
77
|
if (status === 403) {
|
|
66
|
-
|
|
78
|
+
let e = this.createGenericSdkError(body)
|
|
79
|
+
if (!e) {
|
|
80
|
+
e = new SdkError(`You have no access to this resource.`, 403);
|
|
81
|
+
e.response = body;
|
|
82
|
+
}
|
|
83
|
+
throw e;
|
|
67
84
|
}
|
|
68
85
|
if (status === 401) {
|
|
69
|
-
|
|
86
|
+
let e = this.createGenericSdkError(body)
|
|
87
|
+
if (!e) {
|
|
88
|
+
e = new SdkError(`Not authorized.`, 401);
|
|
89
|
+
e.response = body;
|
|
90
|
+
}
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Reads the response as ApiError
|
|
97
|
+
* @param body The message returned by the store.
|
|
98
|
+
* @returns The error schema or undefined when not an error;
|
|
99
|
+
*/
|
|
100
|
+
protected readErrorResponse(body?: string): IApiError | undefined {
|
|
101
|
+
if (!body) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
let data: any;
|
|
105
|
+
try {
|
|
106
|
+
data = JSON.parse(body);
|
|
107
|
+
} catch (e) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
if (data.error && data.message) {
|
|
111
|
+
return data as IApiError;
|
|
112
|
+
}
|
|
113
|
+
return undefined;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
protected createGenericSdkError(body?: string): SdkError | undefined {
|
|
117
|
+
const info = this.readErrorResponse(body);
|
|
118
|
+
if (!info) {
|
|
119
|
+
return undefined;
|
|
70
120
|
}
|
|
121
|
+
const e = new SdkError(info.message, info.code);
|
|
122
|
+
e.detail = info.detail;
|
|
123
|
+
e.response = body;
|
|
124
|
+
return e;
|
|
71
125
|
}
|
|
72
126
|
}
|
|
@@ -1,34 +1,51 @@
|
|
|
1
|
-
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN } from './SdkBase.js';
|
|
1
|
+
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
3
|
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
4
|
+
import { Kind as ProjectKind } from '../../models/Project.js';
|
|
5
|
+
import { Kind as WorkspaceKind } from '../../models/Workspace.js';
|
|
6
|
+
import { IFile } from '../../models/store/File.js';
|
|
7
|
+
import { SdkError } from './Errors.js';
|
|
4
8
|
|
|
5
9
|
export class SharedSdk extends SdkBase {
|
|
6
10
|
/**
|
|
7
11
|
* Lists shared with the user spaces.
|
|
12
|
+
*
|
|
13
|
+
* @param kinds the list of kinds to list. Spaces are always included.
|
|
8
14
|
* @param options Optional query options.
|
|
15
|
+
* @param request Optional request options.
|
|
9
16
|
*/
|
|
10
|
-
async list(options?: IListOptions): Promise<IListResponse
|
|
11
|
-
const
|
|
12
|
-
const url = this.sdk.getUrl(RouteBuilder.
|
|
17
|
+
async list(kinds: (typeof ProjectKind | typeof WorkspaceKind)[], options?: IListOptions, request: ISdkRequestOptions = {}): Promise<IListResponse<IFile>> {
|
|
18
|
+
const token = request.token || this.sdk.token;
|
|
19
|
+
const url = this.sdk.getUrl(RouteBuilder.shared());
|
|
13
20
|
this.sdk.appendListOptions(url, options);
|
|
21
|
+
kinds.forEach(k => url.searchParams.append('kind', k));
|
|
14
22
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
15
|
-
this.inspectCommonStatusCodes(result.status);
|
|
23
|
+
this.inspectCommonStatusCodes(result.status, result.body);
|
|
16
24
|
const E_PREFIX = 'Unable to list spaces. ';
|
|
17
25
|
if (result.status !== 200) {
|
|
18
26
|
this.logInvalidResponse(result);
|
|
19
|
-
|
|
27
|
+
let e = this.createGenericSdkError(result.body)
|
|
28
|
+
if (!e) {
|
|
29
|
+
e = new SdkError(`${E_PREFIX}${E_RESPONSE_STATUS}${result.status}`, result.status);
|
|
30
|
+
e.response = result.body;
|
|
31
|
+
}
|
|
32
|
+
throw e;
|
|
20
33
|
}
|
|
21
34
|
if (!result.body) {
|
|
22
|
-
throw new
|
|
35
|
+
throw new SdkError(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`, 0);
|
|
23
36
|
}
|
|
24
|
-
let data: IListResponse
|
|
37
|
+
let data: IListResponse<IFile>;
|
|
25
38
|
try {
|
|
26
39
|
data = JSON.parse(result.body);
|
|
27
40
|
} catch (e) {
|
|
28
|
-
|
|
41
|
+
const err = new SdkError(`${E_PREFIX}${E_INVALID_JSON}.`, 0);
|
|
42
|
+
err.response = result.body;
|
|
43
|
+
throw err;
|
|
29
44
|
}
|
|
30
45
|
if (!Array.isArray(data.data)) {
|
|
31
|
-
|
|
46
|
+
const err = new SdkError(`${E_PREFIX}${E_RESPONSE_UNKNOWN}.`, 0);
|
|
47
|
+
err.response = result.body;
|
|
48
|
+
throw err;
|
|
32
49
|
}
|
|
33
50
|
return data;
|
|
34
51
|
}
|
|
@@ -5,7 +5,7 @@ import { Http } from './Http.js';
|
|
|
5
5
|
import { WsClient } from './WsClient.js';
|
|
6
6
|
|
|
7
7
|
export { IStoreTokenInfo, IStoreResponse, IStoreRequestOptions } from './SdkBase.js';
|
|
8
|
-
export { ISpaceCreateOptions } from './
|
|
8
|
+
export { IFileCreateOptions as ISpaceCreateOptions } from './FilesSdk.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* NodeJS API for API Client's net-store module.
|
|
@@ -5,7 +5,7 @@ import { Http } from './Http.js';
|
|
|
5
5
|
import { WsClient } from './WsClient.js';
|
|
6
6
|
|
|
7
7
|
export { IStoreTokenInfo, IStoreResponse, IStoreRequestOptions } from './SdkBase.js';
|
|
8
|
-
export { ISpaceCreateOptions } from './
|
|
8
|
+
export { IFileCreateOptions as ISpaceCreateOptions } from './FilesSdk.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* NodeJS API for API Client's net-store module.
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN } from './SdkBase.js';
|
|
1
|
+
import { SdkBase, E_RESPONSE_STATUS, E_RESPONSE_NO_VALUE, E_INVALID_JSON, E_RESPONSE_UNKNOWN, ISdkRequestOptions } from './SdkBase.js';
|
|
2
2
|
import { RouteBuilder } from './RouteBuilder.js';
|
|
3
3
|
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
4
4
|
import { IUser } from '../../models/store/User.js';
|
|
5
5
|
|
|
6
6
|
export class UsersSdk extends SdkBase {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Reads the current user.
|
|
9
|
+
* @param request Optional request options.
|
|
10
|
+
*/
|
|
11
|
+
async me(request: ISdkRequestOptions = {}): Promise<IUser> {
|
|
12
|
+
const token = request.token || this.sdk.token;
|
|
9
13
|
const url = this.sdk.getUrl(RouteBuilder.usersMe());
|
|
10
14
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
11
15
|
this.inspectCommonStatusCodes(result.status);
|
|
@@ -33,9 +37,10 @@ export class UsersSdk extends SdkBase {
|
|
|
33
37
|
* Lists users in the store
|
|
34
38
|
*
|
|
35
39
|
* @param options Optional query options.
|
|
40
|
+
* @param request Optional request options.
|
|
36
41
|
*/
|
|
37
|
-
async list(options?: IListOptions): Promise<IListResponse
|
|
38
|
-
const
|
|
42
|
+
async list(options?: IListOptions, request: ISdkRequestOptions = {}): Promise<IListResponse<IUser>> {
|
|
43
|
+
const token = request.token || this.sdk.token;
|
|
39
44
|
const url = this.sdk.getUrl(RouteBuilder.users());
|
|
40
45
|
this.sdk.appendListOptions(url, options);
|
|
41
46
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
@@ -48,7 +53,7 @@ export class UsersSdk extends SdkBase {
|
|
|
48
53
|
if (!result.body) {
|
|
49
54
|
throw new Error(`${E_PREFIX}${E_RESPONSE_NO_VALUE}`);
|
|
50
55
|
}
|
|
51
|
-
let data: IListResponse
|
|
56
|
+
let data: IListResponse<IUser>;
|
|
52
57
|
try {
|
|
53
58
|
data = JSON.parse(result.body);
|
|
54
59
|
} catch (e) {
|
|
@@ -63,10 +68,11 @@ export class UsersSdk extends SdkBase {
|
|
|
63
68
|
/**
|
|
64
69
|
* Reads a user information from the store.
|
|
65
70
|
* @param key The user key.
|
|
71
|
+
* @param request Optional request options.
|
|
66
72
|
* @returns The user object
|
|
67
73
|
*/
|
|
68
|
-
async read(key: string): Promise<IUser> {
|
|
69
|
-
const
|
|
74
|
+
async read(key: string, request: ISdkRequestOptions = {}): Promise<IUser> {
|
|
75
|
+
const token = request.token || this.sdk.token;
|
|
70
76
|
const url = this.sdk.getUrl(RouteBuilder.user(key));
|
|
71
77
|
const result = await this.sdk.http.get(url.toString(), { token });
|
|
72
78
|
this.inspectCommonStatusCodes(result.status);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
export declare const Kind = "Core#HttpProjectListItem";
|
|
2
|
-
/**
|
|
3
|
-
* The HTTP Project definition to be used in lists.
|
|
4
|
-
*/
|
|
5
|
-
export interface IHttpProjectListItem {
|
|
6
|
-
/**
|
|
7
|
-
* The data store key of the project.
|
|
8
|
-
*/
|
|
9
|
-
key: string;
|
|
10
|
-
/**
|
|
11
|
-
* Project's name
|
|
12
|
-
*/
|
|
13
|
-
name: string;
|
|
14
|
-
/**
|
|
15
|
-
* Whether the project is one of the favourites.
|
|
16
|
-
* May be used by an UI to add projects to favourites.
|
|
17
|
-
*/
|
|
18
|
-
favourite?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* The timestamp when the project was last updated.
|
|
21
|
-
*/
|
|
22
|
-
updated: number;
|
|
23
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HttpProjectListItem.js","sourceRoot":"","sources":["../../../src/models/HttpProjectListItem.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,IAAI,GAAG,0BAA0B,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { JsonPatch } from 'json8-patch';
|
|
2
|
-
import { SdkBase } from './SdkBase.js';
|
|
3
|
-
import { IListOptions, IListResponse } from '../../models/Backend.js';
|
|
4
|
-
import { HttpProject, IHttpProject } from '../../models/HttpProject.js';
|
|
5
|
-
export declare class ProjectsSdk extends SdkBase {
|
|
6
|
-
/**
|
|
7
|
-
* Creates a project in a user space.
|
|
8
|
-
*
|
|
9
|
-
* @param space The user space key
|
|
10
|
-
* @param project THe project to create
|
|
11
|
-
* @returns The key of the created project.
|
|
12
|
-
*/
|
|
13
|
-
create(space: string, project: IHttpProject | HttpProject): Promise<string>;
|
|
14
|
-
/**
|
|
15
|
-
* Reads a project definition from the store.
|
|
16
|
-
* @param space The user space key
|
|
17
|
-
* @param project The project key
|
|
18
|
-
* @returns The definition of the project.
|
|
19
|
-
*/
|
|
20
|
-
read(space: string, project: string): Promise<IHttpProject>;
|
|
21
|
-
/**
|
|
22
|
-
* Lists projects in the space
|
|
23
|
-
*
|
|
24
|
-
* @param space The user space key
|
|
25
|
-
* @param options Optional query options.
|
|
26
|
-
*/
|
|
27
|
-
list(space: string, options?: IListOptions): Promise<IListResponse>;
|
|
28
|
-
/**
|
|
29
|
-
* Deletes a project form the store.
|
|
30
|
-
*
|
|
31
|
-
* @param space The key of the parent space.
|
|
32
|
-
* @param project The key of the project to delete.
|
|
33
|
-
*/
|
|
34
|
-
delete(space: string, project: string): Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Patches a project in the store.
|
|
37
|
-
* @param space The key of the parent user space
|
|
38
|
-
* @param project The key of project to patch.
|
|
39
|
-
* @param value The JSON patch to be processed.
|
|
40
|
-
* @returns The JSON patch to revert the change using the `json8-patch` library
|
|
41
|
-
*/
|
|
42
|
-
patch(space: string, project: string, value: JsonPatch): Promise<JsonPatch>;
|
|
43
|
-
}
|