@edraj/tsdmart 2.0.0 → 2.1.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.
- package/dmart.model.ts +14 -3
- package/dmart.service.ts +25 -23
- package/package.json +1 -1
package/dmart.model.ts
CHANGED
|
@@ -3,6 +3,17 @@ export enum Status {
|
|
|
3
3
|
failed = "failed",
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
export interface ClientError {
|
|
7
|
+
code: string,
|
|
8
|
+
status: string,
|
|
9
|
+
message: string,
|
|
10
|
+
request?: {
|
|
11
|
+
url: string,
|
|
12
|
+
method: string
|
|
13
|
+
},
|
|
14
|
+
response: ApiResponse
|
|
15
|
+
}
|
|
16
|
+
|
|
6
17
|
export type Error = {
|
|
7
18
|
type: string;
|
|
8
19
|
code: number;
|
|
@@ -236,10 +247,10 @@ export enum ContentTypeMedia {
|
|
|
236
247
|
export type Payload = {
|
|
237
248
|
content_type: ContentType;
|
|
238
249
|
schema_shortname?: string;
|
|
239
|
-
checksum
|
|
250
|
+
checksum?: string;
|
|
240
251
|
body: string | Record<string, any> | any;
|
|
241
|
-
last_validated
|
|
242
|
-
validation_status
|
|
252
|
+
last_validated?: string;
|
|
253
|
+
validation_status?: "valid" | "invalid";
|
|
243
254
|
};
|
|
244
255
|
|
|
245
256
|
export type MetaExtended = {
|
package/dmart.service.ts
CHANGED
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
ActionResponse,
|
|
5
5
|
ApiQueryResponse,
|
|
6
6
|
ApiResponse,
|
|
7
|
+
ClientError,
|
|
7
8
|
ContentType,
|
|
8
9
|
headers,
|
|
9
10
|
LoginResponse,
|
|
@@ -16,14 +17,25 @@ import {
|
|
|
16
17
|
Status,
|
|
17
18
|
} from "./dmart.model";
|
|
18
19
|
|
|
19
|
-
|
|
20
20
|
axios.defaults.withCredentials = true;
|
|
21
21
|
axios.defaults.baseURL = "http://localhost:8282";
|
|
22
22
|
|
|
23
|
+
axios.interceptors.response.use(null, function (error) {
|
|
24
|
+
// need error.code (enum), error.status (same), error.message (axios)
|
|
25
|
+
// error.response.data (dmart), error.response.config. method, url,
|
|
26
|
+
const err: ClientError = {
|
|
27
|
+
code: error.code,
|
|
28
|
+
status: error.status,
|
|
29
|
+
message: error.message,
|
|
30
|
+
request: {url: error.response?.config?.url, method: error.response?.config?.method},
|
|
31
|
+
response: error.response?.data
|
|
32
|
+
}
|
|
33
|
+
return Promise.reject(err);
|
|
34
|
+
});
|
|
23
35
|
export const dmartClient = axios;
|
|
24
36
|
|
|
25
37
|
export class Dmart {
|
|
26
|
-
// static baseURL = "http://localhost:8282";
|
|
38
|
+
// static baseURL = "http://localhost:8282";
|
|
27
39
|
|
|
28
40
|
public static async login(shortname: string, password: string) {
|
|
29
41
|
try {
|
|
@@ -114,12 +126,9 @@ export class Dmart {
|
|
|
114
126
|
|
|
115
127
|
public static async get_profile() {
|
|
116
128
|
try {
|
|
117
|
-
const { data } = await axios.get<ProfileResponse>(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
headers,
|
|
121
|
-
}
|
|
122
|
-
);
|
|
129
|
+
const { data } = await axios.get<ProfileResponse>(`user/profile`, {
|
|
130
|
+
headers,
|
|
131
|
+
});
|
|
123
132
|
if (typeof localStorage !== "undefined" && data.status === "success") {
|
|
124
133
|
localStorage.setItem(
|
|
125
134
|
"permissions",
|
|
@@ -187,16 +196,10 @@ export class Dmart {
|
|
|
187
196
|
}
|
|
188
197
|
|
|
189
198
|
public static async request(action: ActionRequest): Promise<ActionResponse> {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
{ headers }
|
|
195
|
-
);
|
|
196
|
-
return data;
|
|
197
|
-
} catch (error: any) {
|
|
198
|
-
throw error;
|
|
199
|
-
}
|
|
199
|
+
const res = await axios.post<ActionResponse>(`managed/request`, action, {
|
|
200
|
+
headers,
|
|
201
|
+
});
|
|
202
|
+
return res?.data;
|
|
200
203
|
}
|
|
201
204
|
|
|
202
205
|
public static async retrieve_entry(
|
|
@@ -229,7 +232,8 @@ export class Dmart {
|
|
|
229
232
|
resource_type: ResourceType,
|
|
230
233
|
payload_file: File,
|
|
231
234
|
content_type?: ContentType,
|
|
232
|
-
schema_shortname?: string
|
|
235
|
+
schema_shortname?: string,
|
|
236
|
+
scope: string = "managed"
|
|
233
237
|
): Promise<ApiResponse> {
|
|
234
238
|
const request_record_body: any = {
|
|
235
239
|
resource_type,
|
|
@@ -258,7 +262,7 @@ export class Dmart {
|
|
|
258
262
|
|
|
259
263
|
try {
|
|
260
264
|
const { data } = await axios.post<ApiResponse>(
|
|
261
|
-
|
|
265
|
+
`${scope}/resource_with_payload`,
|
|
262
266
|
form_data,
|
|
263
267
|
{ headers }
|
|
264
268
|
);
|
|
@@ -276,8 +280,7 @@ export class Dmart {
|
|
|
276
280
|
subpath: string,
|
|
277
281
|
shortname: string,
|
|
278
282
|
query_string?: string,
|
|
279
|
-
filter_data_assets?: string[]
|
|
280
|
-
branch_name?: string
|
|
283
|
+
filter_data_assets?: string[]
|
|
281
284
|
) {
|
|
282
285
|
try {
|
|
283
286
|
const url = `managed/data-asset`;
|
|
@@ -291,7 +294,6 @@ export class Dmart {
|
|
|
291
294
|
shortname,
|
|
292
295
|
query_string: query_string ?? "SELECT * FROM file",
|
|
293
296
|
filter_data_assets,
|
|
294
|
-
branch_name,
|
|
295
297
|
},
|
|
296
298
|
{ headers }
|
|
297
299
|
);
|