@jdr-web-infra/joyspace-docs-web-api 0.0.0-stage → 0.0.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.
@@ -0,0 +1,72 @@
1
+ export declare const BASE_URL = "https://apijoyspace.jd.com";
2
+ export declare const API_SUCCESS_STATUS = "success";
3
+ interface PageAuthor {
4
+ id: string;
5
+ name: string;
6
+ avatar_url: string;
7
+ isExternal: boolean;
8
+ }
9
+ interface PageSettings {
10
+ linkShareMode: string;
11
+ crossTenantShareAllowed: string;
12
+ canApplyPermission: string;
13
+ permissionApplyAllowed: string;
14
+ }
15
+ interface PageBasic {
16
+ id: string;
17
+ title: string;
18
+ cover_img_url: string;
19
+ summary: string;
20
+ preview_text: string;
21
+ tenant_id: string;
22
+ team_id: string;
23
+ folder_id: string;
24
+ space_id: string;
25
+ template_id: string;
26
+ cycle: number;
27
+ page_type: number;
28
+ page_status: string;
29
+ created_by: string;
30
+ updated_by: string;
31
+ published_by: string;
32
+ origin_id: string;
33
+ origin_author: string;
34
+ created_at: string;
35
+ updated_at: string;
36
+ published_at: string;
37
+ status: string;
38
+ tags: string;
39
+ tight_flag: number;
40
+ reachable_path: string;
41
+ author: PageAuthor;
42
+ isCollected: boolean;
43
+ isShortcuted: boolean;
44
+ isFollowed: boolean;
45
+ inOpenTeam: number;
46
+ isPublic: number;
47
+ isOwner: boolean;
48
+ followCount: number;
49
+ permissions: string[];
50
+ settings: PageSettings;
51
+ fullPath: string;
52
+ amount: number;
53
+ isParent: number;
54
+ isFolder: number;
55
+ advancedPermission: number;
56
+ blockId2Permission: Record<string, unknown>;
57
+ embedLink: Record<string, unknown>;
58
+ webIcon: string;
59
+ mobileIcon: string;
60
+ link: string;
61
+ }
62
+ export declare function createApplication(userToken?: string): {
63
+ /**
64
+ * 获取文档页面基础信息
65
+ *
66
+ * @param pageId 文档页面 ID
67
+ * @param sendRecent 是否写入最近访问,0 为不写入
68
+ */
69
+ getPageBasic(pageId: string, sendRecent?: number): Promise<PageBasic>;
70
+ };
71
+ export type Application = ReturnType<typeof createApplication>;
72
+ export type { PageAuthor, PageBasic, PageSettings };
package/dist/index.mjs ADDED
@@ -0,0 +1,57 @@
1
+ import { create, isAxiosError } from "axios";
2
+
3
+ // src/config.ts
4
+ const BASE_URL = "https://apijoyspace.jd.com";
5
+ const API_SUCCESS_STATUS = "success";
6
+
7
+ // src/index.ts
8
+ function errorFromMessage(message, fallback = "请求失败") {
9
+ return new Error(typeof message === "string" && message ? message : fallback);
10
+ }
11
+ function errorFromRequest(error) {
12
+ const data = isAxiosError(error) ? error.response?.data : void 0;
13
+ return errorFromMessage(data && typeof data === "object" ? data.errMsg ?? data.message : void 0, error instanceof Error ? error.message : "请求失败");
14
+ }
15
+ function unwrapData(body) {
16
+ const { status, message, errMsg, data } = body ?? {};
17
+ if (status !== "success") throw errorFromMessage(errMsg ?? message);
18
+ return data;
19
+ }
20
+ async function readData(response) {
21
+ try {
22
+ const { data } = await response;
23
+ return unwrapData(data);
24
+ } catch (error) {
25
+ if (!isAxiosError(error)) throw error;
26
+ throw errorFromRequest(error);
27
+ }
28
+ }
29
+ function createClient(userToken) {
30
+ let cookie = "sso.jd.com=";
31
+ if (userToken) cookie += userToken;
32
+ else if (process.env.SSO_JD_COM) cookie += process.env.SSO_JD_COM;
33
+ else throw new Error("用户凭据丢失");
34
+ return create({
35
+ baseURL: BASE_URL,
36
+ headers: {
37
+ Accept: "application/json",
38
+ "Content-Type": "application/json",
39
+ Cookie: cookie
40
+ }
41
+ });
42
+ }
43
+ function createApplication(userToken) {
44
+ const axiosInstance = createClient(userToken);
45
+ return {
46
+ /**
47
+ * 获取文档页面基础信息
48
+ *
49
+ * @param pageId 文档页面 ID
50
+ * @param sendRecent 是否写入最近访问,0 为不写入
51
+ */
52
+ getPageBasic(pageId, sendRecent = 0) {
53
+ return readData(axiosInstance.get(`/v3/pages/${encodeURIComponent(pageId)}/basic`, { params: { sendRecent } }));
54
+ } };
55
+ }
56
+
57
+ export { API_SUCCESS_STATUS, BASE_URL, createApplication };
package/package.json CHANGED
@@ -1,6 +1,34 @@
1
1
  {
2
2
  "name": "@jdr-web-infra/joyspace-docs-web-api",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.0.1",
4
+ "files": [
5
+ "dist"
6
+ ],
7
+ "type": "module",
8
+ "exports": {
9
+ ".": "./dist/index.mjs",
10
+ "./package.json": "./package.json"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "registry": "https://registry.npmjs.org"
15
+ },
16
+ "dependencies": {
17
+ "axios": "1.21.1"
18
+ },
19
+ "devDependencies": {
20
+ "@liangmi/vp-config": "1.0.1",
21
+ "@types/node": "26.6.6",
22
+ "@vitest/coverage-v8": "5.1.0",
23
+ "typescript": "7.0.2",
24
+ "vite-plus": "1.7.0"
25
+ },
26
+ "devEngines": {
27
+ "packageManager": {
28
+ "name": "pnpm",
29
+ "version": "12.21.0",
30
+ "onFail": "download"
31
+ }
32
+ },
33
+ "scripts": {}
6
34
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.