@jdr-web-infra/xingyun-open-api-user 0.0.3 → 0.0.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/dist/index.d.mts CHANGED
@@ -87,9 +87,7 @@ interface UserVO {
87
87
  positionName: string;
88
88
  quited: number;
89
89
  }
90
- declare class Application {
91
- private axiosInstance;
92
- constructor(userToken?: string);
90
+ export declare function createApplication(userToken?: string): {
93
91
  /**
94
92
  * 按卡片ID查询卡片详情(含所属空间、迭代、阶段、扩展字段及关联附件)
95
93
  *
@@ -118,5 +116,5 @@ declare class Application {
118
116
  * @returns
119
117
  */
120
118
  querySprintsBySpaceId(spaceId: string): Promise<Sprint[]>;
121
- }
122
- export { type Card, type Space, type Sprint, type SprintInfo, type UserVO, Application as default };
119
+ };
120
+ export type { Card, Space, Sprint, SprintInfo, UserVO };
package/dist/index.mjs CHANGED
@@ -1,74 +1,84 @@
1
1
  import { create, isAxiosError } from "axios";
2
+
2
3
  // src/config.ts
3
4
  const BASE_URL = "http://api-gateway.jd.com/jacp";
4
5
  const APP_ID = "joyclaw";
5
6
  const CONTENT_TYPE = "application/json";
6
7
  const API_SUCCESS_CODE = 200;
8
+
7
9
  // src/index.ts
8
- var Application = class {
9
- axiosInstance;
10
- constructor(userToken) {
11
- let cookie = "sso.jd.com=";
12
- if (userToken) cookie += userToken;
13
- else if (process.env.SSO_JD_COM) cookie += process.env.SSO_JD_COM;
14
- else throw new Error("用户凭据丢失");
15
- const axiosInstance = create({
16
- baseURL: BASE_URL,
17
- headers: {
18
- appId: APP_ID,
19
- Cookie: cookie,
20
- "Content-Type": CONTENT_TYPE
21
- }
22
- });
23
- const rejectByMessage = (message, fallback = "请求失败") => Promise.reject(new Error(typeof message === "string" && message ? message : fallback));
24
- axiosInstance.interceptors.response.use((response) => {
25
- const { code, message, data } = response.data ?? {};
26
- if (code !== 200) return rejectByMessage(message);
27
- response.data = data;
28
- return response;
29
- }, (error) => {
30
- const data = isAxiosError(error) ? error.response?.data : void 0;
31
- const message = data && typeof data === "object" ? data.message : void 0;
32
- const fallback = error instanceof Error ? error.message : "请求失败";
33
- return rejectByMessage(message, fallback);
34
- });
35
- this.axiosInstance = axiosInstance;
10
+ function resolveCookie(userToken) {
11
+ if (userToken) return `sso.jd.com=${userToken}`;
12
+ if (process.env.SSO_JD_COM) return `sso.jd.com=${process.env.SSO_JD_COM}`;
13
+ throw new Error("用户凭据丢失");
14
+ }
15
+ function errorFromMessage(message, fallback = "请求失败") {
16
+ return new Error(typeof message === "string" && message ? message : fallback);
17
+ }
18
+ function readApiBody(value) {
19
+ if (typeof value === "object" && value !== null) return value;
20
+ return {};
21
+ }
22
+ function createClient(userToken) {
23
+ return create({
24
+ baseURL: BASE_URL,
25
+ headers: {
26
+ appId: APP_ID,
27
+ Cookie: resolveCookie(userToken),
28
+ "Content-Type": CONTENT_TYPE
29
+ }
30
+ });
31
+ }
32
+ async function getJson(axiosInstance, url) {
33
+ try {
34
+ const body = readApiBody((await axiosInstance.get(url)).data);
35
+ if (body.code !== 200) throw errorFromMessage(body.message);
36
+ return body.data;
37
+ } catch (error) {
38
+ if (!isAxiosError(error)) throw error instanceof Error ? error : errorFromMessage();
39
+ throw errorFromMessage(readApiBody(error.response?.data).message, error.message);
36
40
  }
37
- /**
38
- * 按卡片ID查询卡片详情(含所属空间、迭代、阶段、扩展字段及关联附件)
39
- *
40
- * @param cardId
41
- * @returns
42
- */
43
- async getCardById(cardId) {
44
- return (await this.axiosInstance.get(`/openapi/v3/cards/${cardId}`)).data;
45
- }
46
- /**
47
- * 按空间ID查询空间信息
48
- *
49
- * @param spaceId 空间ID
50
- * @returns
51
- */
52
- async getSpaceById(spaceId) {
53
- return (await this.axiosInstance.get(`/openapi/v3/spaces/${spaceId}`)).data;
54
- }
55
- /**
56
- * 按迭代ID查询迭代信息
57
- *
58
- * @param sprintId 迭代ID
59
- * @returns
60
- */
61
- async getSprintById(sprintId) {
62
- return (await this.axiosInstance.get(`/openapi/v3/sprints/${sprintId}`)).data;
63
- }
64
- /**
65
- * 查询指定空间下的迭代列表
66
- *
67
- * @param spaceId 空间 ID
68
- * @returns
69
- */
70
- async querySprintsBySpaceId(spaceId) {
71
- return (await this.axiosInstance.get(`/openapi/v3/spaces/${spaceId}/sprints`)).data;
72
- }
73
- };
74
- export { API_SUCCESS_CODE, APP_ID, BASE_URL, CONTENT_TYPE, Application as default };
41
+ }
42
+ function createApplication(userToken) {
43
+ const axiosInstance = createClient(userToken);
44
+ return {
45
+ /**
46
+ * 按卡片ID查询卡片详情(含所属空间、迭代、阶段、扩展字段及关联附件)
47
+ *
48
+ * @param cardId
49
+ * @returns
50
+ */
51
+ getCardById(cardId) {
52
+ return getJson(axiosInstance, `/openapi/v3/cards/${cardId}`);
53
+ },
54
+ /**
55
+ * 按空间ID查询空间信息
56
+ *
57
+ * @param spaceId 空间ID
58
+ * @returns
59
+ */
60
+ getSpaceById(spaceId) {
61
+ return getJson(axiosInstance, `/openapi/v3/spaces/${spaceId}`);
62
+ },
63
+ /**
64
+ * 按迭代ID查询迭代信息
65
+ *
66
+ * @param sprintId 迭代ID
67
+ * @returns
68
+ */
69
+ getSprintById(sprintId) {
70
+ return getJson(axiosInstance, `/openapi/v3/sprints/${sprintId}`);
71
+ },
72
+ /**
73
+ * 查询指定空间下的迭代列表
74
+ *
75
+ * @param spaceId 空间 ID
76
+ * @returns
77
+ */
78
+ querySprintsBySpaceId(spaceId) {
79
+ return getJson(axiosInstance, `/openapi/v3/spaces/${spaceId}/sprints`);
80
+ }
81
+ };
82
+ }
83
+
84
+ export { API_SUCCESS_CODE, APP_ID, BASE_URL, CONTENT_TYPE, createApplication };
package/package.json CHANGED
@@ -1,10 +1,6 @@
1
1
  {
2
2
  "name": "@jdr-web-infra/xingyun-open-api-user",
3
- "version": "0.0.3",
4
- "repository": {
5
- "type": "git",
6
- "url": "git+https://github.com/jdr-web-infra/xingyun-open-api-user.git"
7
- },
3
+ "version": "0.0.5",
8
4
  "files": [
9
5
  "dist"
10
6
  ],
@@ -20,8 +16,9 @@
20
16
  "axios": "1.21.1"
21
17
  },
22
18
  "devDependencies": {
23
- "@types/node": "^26.6.5",
24
- "typescript": "^7.0.2",
19
+ "@liangmi/vp-config": "1.0.1",
20
+ "@types/node": "26.6.6",
21
+ "typescript": "7.0.2",
25
22
  "vite-plus": "1.7.0"
26
23
  },
27
24
  "devEngines": {
@@ -33,8 +30,8 @@
33
30
  },
34
31
  "scripts": {
35
32
  "build": "vp pack",
33
+ "check": "vp check",
36
34
  "dev": "vp pack --watch",
37
- "test": "vp test",
38
- "check": "vp check"
35
+ "test": "vp test"
39
36
  }
40
37
  }
package/README.md DELETED
@@ -1,43 +0,0 @@
1
- # xingyun-open-api-user
2
-
3
- <!-- automd:badges bundlephobia -->
4
-
5
- [![npm version](https://img.shields.io/npm/v/@jdr-web-infra/xingyun-open-api-user)](https://npmjs.com/package/@jdr-web-infra/xingyun-open-api-user)
6
- [![npm downloads](https://img.shields.io/npm/dm/@jdr-web-infra/xingyun-open-api-user)](https://npm.chart.dev/@jdr-web-infra/xingyun-open-api-user)
7
- [![bundle size](https://img.shields.io/bundlephobia/minzip/@jdr-web-infra/xingyun-open-api-user)](https://bundlephobia.com/package/@jdr-web-infra/xingyun-open-api-user)
8
-
9
- <!-- /automd -->
10
-
11
- ## Usage
12
-
13
- <!-- automd:pm-install -->
14
-
15
- ```sh
16
- # ✨ Auto-detect
17
- npx nypm install @jdr-web-infra/xingyun-open-api-user
18
-
19
- # npm
20
- npm install @jdr-web-infra/xingyun-open-api-user
21
-
22
- # yarn
23
- yarn add @jdr-web-infra/xingyun-open-api-user
24
-
25
- # pnpm
26
- pnpm add @jdr-web-infra/xingyun-open-api-user
27
-
28
- # bun
29
- bun install @jdr-web-infra/xingyun-open-api-user
30
-
31
- # deno
32
- deno install npm:@jdr-web-infra/xingyun-open-api-user
33
- ```
34
-
35
- <!-- /automd -->
36
-
37
- <!-- automd:with-automd -->
38
-
39
- ---
40
-
41
- _🤖 auto updated with [automd](https://automd.unjs.io)_
42
-
43
- <!-- /automd -->