@edraj/tsdmart 3.0.0 → 4.0.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edraj/tsdmart",
3
- "version": "3.0.0",
3
+ "version": "4.0.0",
4
4
  "description": "A TypeScript implementation of the Dmart that depends on axios.",
5
5
  "author": "Kefah T. Issa",
6
6
  "email": "kefah.issa@gmail.com",
@@ -11,16 +11,16 @@
11
11
  },
12
12
  "type": "module",
13
13
  "devDependencies": {
14
- "@types/node": "^22.15.3",
15
- "@typescript-eslint/eslint-plugin": "^8.31.1",
16
- "@typescript-eslint/parser": "^8.31.1",
17
- "eslint": "^9.25.1",
14
+ "@types/node": "^24.2.1",
15
+ "@typescript-eslint/eslint-plugin": "^8.39.1",
16
+ "@typescript-eslint/parser": "^8.39.1",
17
+ "eslint": "^9.33.0",
18
18
  "ts-node": "^10.9.2",
19
19
  "tsconfig-paths": "^4.2.0",
20
20
  "tslib": "^2.8.1",
21
- "typescript": "^5.8.3"
21
+ "typescript": "^5.9.2"
22
22
  },
23
23
  "dependencies": {
24
- "axios": "^1.9.0"
24
+ "axios": "^1.11.0"
25
25
  }
26
26
  }
package/client.ts DELETED
@@ -1,114 +0,0 @@
1
- import axios, { AxiosInstance, CreateAxiosDefaults } from "axios";
2
- import { Config } from "./config";
3
- import {
4
- ActionRequest,
5
- ClientError,
6
- ContentType,
7
- QueryRequest,
8
- ResourceType,
9
- } from "./dmart.model";
10
- import { get_profile, login, logout } from "./services/auth";
11
- import { query, retrieve_entry } from "./services/query";
12
- import { request, submit } from "./services/request";
13
- import { upload_with_payload } from "./services/upload";
14
-
15
- export class DmartClient {
16
- client: AxiosInstance;
17
-
18
- constructor(config: CreateAxiosDefaults) {
19
- this.client = axios.create({ ...Config, ...config });
20
-
21
- this.client.interceptors.response.use(null, function (error) {
22
- // need error.code (enum), error.status (same), error.message (axios)
23
- // error.response.data (dmart), error.response.config. method, url,
24
- const err: ClientError = {
25
- code: error.code,
26
- status: error.status,
27
- message: error.message,
28
- request: {
29
- url: error.response?.config?.url,
30
- method: error.response?.config?.method,
31
- },
32
- response: error.response?.data,
33
- };
34
- return Promise.reject(err);
35
- });
36
- }
37
-
38
- async login(shortname: string, password: string) {
39
- return login(shortname, password, this.client);
40
- }
41
-
42
- async get_profile() {
43
- return get_profile(this.client);
44
- }
45
-
46
- async logout() {
47
- return logout(this.client);
48
- }
49
-
50
- async query(q: QueryRequest, scope: string = "managed") {
51
- return query(this.client, q, scope);
52
- }
53
-
54
- async retrieve_entry(
55
- resource_type: ResourceType,
56
- space_name: string,
57
- subpath: string,
58
- shortname: string,
59
- retrieve_json_payload: boolean = false,
60
- retrieve_attachments: boolean = false,
61
- validate_schema: boolean = true,
62
- scope: string = "managed"
63
- ) {
64
- return retrieve_entry(
65
- this.client,
66
- resource_type,
67
- space_name,
68
- subpath,
69
- shortname,
70
- retrieve_json_payload,
71
- retrieve_attachments,
72
- validate_schema,
73
- scope
74
- );
75
- }
76
-
77
- async upload_with_payload(
78
- space_name: string,
79
- subpath: string,
80
- shortname: string,
81
- resource_type: ResourceType,
82
- payload_file: File,
83
- content_type?: ContentType,
84
- schema_shortname?: string,
85
- scope: string = "managed"
86
- ) {
87
- return upload_with_payload(
88
- this.client,
89
- space_name,
90
- subpath,
91
- shortname,
92
- resource_type,
93
- payload_file,
94
- content_type,
95
- schema_shortname,
96
- scope
97
- );
98
- }
99
-
100
- async request(action: ActionRequest) {
101
- return request(this.client, action);
102
- }
103
-
104
- async submit(
105
- spaceName: string,
106
- schemaShortname: string,
107
- subpath: string,
108
- record: any,
109
- resourceType?: string,
110
- workflowShortname?: string
111
- ) {
112
- return submit(this.client, spaceName, schemaShortname, subpath, record, resourceType, workflowShortname);
113
- }
114
- }
package/services/auth.ts DELETED
@@ -1,45 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
- import { Config } from '../config';
3
- import {
4
- ApiResponse,
5
- headers,
6
- LoginResponse,
7
- ProfileResponse,
8
- Status,
9
- } from "../dmart.model";
10
-
11
- export const login = async (
12
- shortname: string,
13
- password: string,
14
- client: AxiosInstance
15
- ) => {
16
- // use which client? defaultAxios if what?
17
- const response = await client.post<LoginResponse>(
18
- `user/login`,
19
- { shortname, password },
20
- { headers: Config.headers }
21
- );
22
- const data: LoginResponse = response.data;
23
- if (data.status == Status.success && data.records.length > 0) {
24
- headers["Authorization"] =
25
- "Bearer " + data.records[0]?.attributes.access_token;
26
- }
27
- return data;
28
- };
29
-
30
- export const get_profile = async (client: AxiosInstance) => {
31
- const { data } = await client.get<ProfileResponse>(`user/profile`, {
32
- headers: Config.headers,
33
- });
34
-
35
- return data;
36
- };
37
-
38
- export const logout = async (client: AxiosInstance) => {
39
- const { data } = await client.post<ApiResponse>(
40
- `user/logout`,
41
- {},
42
- { headers: Config.headers }
43
- );
44
- return data;
45
- };
package/services/query.ts DELETED
@@ -1,53 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
- import { Config } from '../config';
3
- import {
4
- ApiQueryResponse,
5
- QueryRequest,
6
- QueryType,
7
- ResourceType,
8
- ResponseEntry,
9
- SortyType,
10
- } from "../dmart.model";
11
-
12
- export const query = async (
13
- client: AxiosInstance,
14
- query: QueryRequest,
15
- scope: string = "managed"
16
- ): Promise<ApiQueryResponse | null> => {
17
- if (query.type !== QueryType.spaces) {
18
- query.sort_type = query.sort_type || SortyType.ascending;
19
- query.sort_by = query.sort_by || "created_at";
20
- }
21
-
22
- // bad!
23
- query.subpath = query.subpath.replace(/\/+/g, "/");
24
- const { data } = await client.post<ApiQueryResponse>(
25
- `${scope}/query`,
26
- query,
27
- {
28
- headers: Config.headers,
29
- timeout: 3000,
30
- }
31
- );
32
- return data;
33
- };
34
-
35
- export const retrieve_entry = async (
36
- client: AxiosInstance,
37
- resource_type: ResourceType,
38
- space_name: string,
39
- subpath: string,
40
- shortname: string,
41
- retrieve_json_payload: boolean = false,
42
- retrieve_attachments: boolean = false,
43
- validate_schema: boolean = true,
44
- scope: string = "managed"
45
- ): Promise<ResponseEntry | null> => {
46
- if (!subpath || subpath == "/") subpath = "__root__";
47
- const url = `${scope}/entry/${resource_type}/${space_name}/${subpath}/${shortname}?retrieve_json_payload=${retrieve_json_payload}&retrieve_attachments=${retrieve_attachments}&validate_schema=${validate_schema}`;
48
- const { data } = await client.get<ResponseEntry>(
49
- `${url.replace(/\/+/g, "/")}`,
50
- { headers: Config.headers }
51
- );
52
- return data;
53
- };
@@ -1,54 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
- import { Config } from '../config';
3
- import { ActionRequest, ActionResponse } from "../dmart.model";
4
-
5
- export const request = async (
6
- client: AxiosInstance,
7
- action: ActionRequest
8
- ): Promise<ActionResponse> => {
9
- const res = await client.post<ActionResponse>(`managed/request`, action, {
10
- headers: Config.headers,
11
- });
12
- return res?.data;
13
- };
14
-
15
- // export const submit = async (
16
- // client: AxiosInstance,
17
- // spaceName: string,
18
- // schemaShortname: string,
19
- // subpath: string,
20
- // record: any
21
- // ) => {
22
- // const { data } = await client.post(
23
- // `public/submit/${spaceName}/${schemaShortname}/${subpath}`,
24
- // record,
25
- // { headers: Config.headers }
26
- // );
27
- // return data;
28
- // };
29
-
30
-
31
- export const submit = async (
32
- client: AxiosInstance,
33
- spaceName: string,
34
- schemaShortname: string,
35
- subpath: string,
36
- record: any,
37
- resourceType?: string,
38
- workflowShortname?: string,
39
- ) => {
40
- let url = `public/submit/${spaceName}`;
41
- if (resourceType) {
42
- url += `/${resourceType}`;
43
- }
44
- if (workflowShortname) {
45
- url += `/${workflowShortname}`;
46
- }
47
- url += `/${schemaShortname}/${subpath}`;
48
- const { data } = await client.post(
49
- url,
50
- record,
51
- { headers: Config.headers }
52
- );
53
- return data;
54
- };
@@ -1,46 +0,0 @@
1
- import { AxiosInstance } from "axios";
2
- import { ApiResponse, ContentType, ResourceType } from "../dmart.model";
3
-
4
- export const upload_with_payload = async (
5
- client: AxiosInstance,
6
- space_name: string,
7
- subpath: string,
8
- shortname: string,
9
- resource_type: ResourceType,
10
- payload_file: File,
11
- content_type?: ContentType,
12
- schema_shortname?: string,
13
- scope: string = "managed"
14
- ): Promise<ApiResponse> => {
15
- const request_record_body: any = {
16
- resource_type,
17
- subpath,
18
- shortname,
19
- attributes: { is_active: true, payload: { body: {} } },
20
- };
21
- if (content_type) {
22
- request_record_body.attributes.payload.content_type = content_type;
23
- }
24
- if (schema_shortname) {
25
- request_record_body.attributes.payload.schema_shortname = schema_shortname;
26
- }
27
-
28
- const request_record = new Blob([JSON.stringify(request_record_body)], {
29
- type: "application/json",
30
- });
31
-
32
- const form_data = new FormData();
33
- form_data.append("space_name", space_name);
34
- form_data.append("request_record", request_record);
35
- form_data.append("payload_file", payload_file);
36
-
37
- const headers = { "Content-Type": "multipart/form-data" };
38
-
39
- const { data } = await client.post<ApiResponse>(
40
- `${scope}/resource_with_payload`,
41
- form_data,
42
- { headers }
43
- );
44
-
45
- return data;
46
- };
package/services/user.ts DELETED
@@ -1,12 +0,0 @@
1
- import { AxiosInstance } from 'axios';
2
- import { Config } from '../config';
3
- import { ApiResponse } from '../dmart.model';
4
-
5
- export const create_user = async (client: AxiosInstance) => {
6
- const { data } = await client.post<ApiResponse>(
7
- `user/logout`,
8
- {},
9
- { headers: Config.headers }
10
- );
11
- return data;
12
- };