icms-api 0.1.3 → 0.1.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.
@@ -0,0 +1,78 @@
1
+ /**
2
+ * 客户端 HTTP 辅助函数
3
+ * 从 @rock.chen/icms-http-client/web-client 内联,
4
+ * 避免引入 pino/pino-pretty/sonic-boom 等 Node.js 服务端模块
5
+ */
6
+ /** Cookie 读写接口 */
7
+ export interface ICookies {
8
+ get(key: string): string | undefined;
9
+ set?(key: string, value: string): void;
10
+ delete?(key: string): void;
11
+ }
12
+ /** API 返回模型 */
13
+ export interface ResultModel<T = unknown> {
14
+ code: number;
15
+ success: boolean;
16
+ msg: string;
17
+ data?: T;
18
+ headers?: Record<string, string>;
19
+ }
20
+ /** GET 请求参数 */
21
+ export interface ClientGetParams {
22
+ data?: Record<string, string>;
23
+ headers?: Record<string, string>;
24
+ useCache?: boolean;
25
+ showError?: (msg: string) => void;
26
+ }
27
+ /** POST 请求参数 */
28
+ export interface ClientPostParams {
29
+ data?: Record<string, unknown> | FormData;
30
+ headers?: Record<string, string>;
31
+ showError?: (msg: string) => void;
32
+ showSuccess?: (msg: string) => void;
33
+ }
34
+ /** Cookie 名称常量 */
35
+ export declare const COOKIE_NAMES: {
36
+ readonly IBOOT_DEVICE_ID: "dvid";
37
+ readonly IBOOT_LANG: "lang";
38
+ readonly IBOOT_WEBSITE_ID: "wid";
39
+ readonly IBOOT_WEBSITE_NO: "wno";
40
+ readonly IBOOT_TOKEN: "token";
41
+ readonly IBOOT_USER: "user";
42
+ };
43
+ /** Content-Type 常量 */
44
+ export declare const CONTENT_TYPE_KEY = "Content-Type";
45
+ export declare const CONTENT_TYPE_MAP: {
46
+ readonly applicationJson: "application/json";
47
+ readonly multipartFormData: "multipart/form-data";
48
+ readonly applicationXwwwFormUrlencoded: "application/x-www-form-urlencoded";
49
+ };
50
+ /** 用户信息 */
51
+ export interface User {
52
+ id: string;
53
+ name: string;
54
+ userType: number;
55
+ username?: string;
56
+ nickname?: string;
57
+ sex?: number;
58
+ headImg?: string;
59
+ lastLoginTime?: string;
60
+ tokenExpired?: string;
61
+ deviceId?: string;
62
+ status?: number;
63
+ accountType?: number;
64
+ enabled?: boolean;
65
+ userFrom?: number;
66
+ needToReview?: boolean;
67
+ socketOnline?: boolean;
68
+ createTime?: string;
69
+ mustChangePwd?: boolean;
70
+ }
71
+ /** 从 cookie 中读取已登录用户信息 */
72
+ export declare const getLoginUser: (cookies: ICookies) => User | undefined;
73
+ /** GET 请求快捷方法(自动解包 data) */
74
+ export declare const iGet: <T>(url: string, opts?: ClientGetParams) => Promise<T | undefined>;
75
+ /** POST 请求快捷方法(自动解包 data) */
76
+ export declare const iPost: <T>(url: string, opts?: ClientPostParams) => Promise<T | undefined>;
77
+ /** POST 请求,返回 boolean */
78
+ export declare const iPostSuccess: (url: string, opts?: ClientPostParams) => Promise<boolean>;
@@ -6,8 +6,8 @@ import { PhotoContent } from './types/cms-photo';
6
6
  import { VideoContent } from './types/cms-video';
7
7
  import { ActivityContent } from './types/cms-activity';
8
8
  import { Reviews, SubscribeUser, ContactUs } from './types/cms-message';
9
- import { SpecDescription } from './types/cms-mall';
10
- import { ICookies } from '@rock.chen/icms-http-client';
9
+ import { SpecDescription, GoodsItem, GoodsCategory, GoodsTag } from './types/cms-mall';
10
+ import { ICookies } from './client-helper';
11
11
  export declare class ICMSClient {
12
12
  private cookies;
13
13
  constructor();
@@ -105,5 +105,19 @@ export declare class ICMSClient {
105
105
  loadFriendLinks(count?: number): Promise<Array<FriendLink>>;
106
106
  submitLink(data: Readonly<Pick<FriendLink, 'name' | 'url'> & Partial<Pick<FriendLink, 'description'>>>): Promise<boolean>;
107
107
  getSpecDescription(code: string): Promise<SpecDescription | undefined>;
108
+ /** 获取商品标签字典 */
109
+ loadGoodsTagList(): Promise<Array<GoodsTag>>;
110
+ /** 获取所有货架(类目)列表 */
111
+ loadGoodsShelves(): Promise<Array<GoodsCategory>>;
112
+ /** 获取指定货架的商品列表 */
113
+ loadCategoryGoods(params: Readonly<{
114
+ cateCode: string;
115
+ count?: number;
116
+ }>): Promise<Array<GoodsItem>>;
117
+ /** 分页搜索商品 */
118
+ searchGoods(params: Readonly<{
119
+ cateCode?: string;
120
+ keyword?: string;
121
+ } & PageParams>): Promise<PageInfo<GoodsItem> | undefined>;
108
122
  }
109
123
  export declare const icmsClient: ICMSClient;
@@ -7,7 +7,7 @@ import { PhotoContent } from './types/cms-photo';
7
7
  import { VideoContent } from './types/cms-video';
8
8
  import { ActivityContent } from './types/cms-activity';
9
9
  import { Reviews, SubscribeUser, ContactUs } from './types/cms-message';
10
- import { SpecDescription } from './types/cms-mall';
10
+ import { SpecDescription, GoodsItem, GoodsCategory, GoodsTag } from './types/cms-mall';
11
11
  export declare const helloURL: string;
12
12
  export declare class ICMSServer {
13
13
  private readonly http;
@@ -260,4 +260,18 @@ export declare class ICMSServer {
260
260
  * @param code 规格编码
261
261
  */
262
262
  getSpecDescription(code: string): Promise<SpecDescription | undefined>;
263
+ /** 获取商品标签字典 */
264
+ loadGoodsTagList(): Promise<Array<GoodsTag>>;
265
+ /** 获取所有货架(类目)列表 */
266
+ loadGoodsShelves(): Promise<Array<GoodsCategory>>;
267
+ /** 获取指定货架的商品列表 */
268
+ loadCategoryGoods(params: Readonly<{
269
+ cateCode: string;
270
+ count?: number;
271
+ }>): Promise<Array<GoodsItem>>;
272
+ /** 分页搜索商品 */
273
+ searchGoods(params: Readonly<{
274
+ cateCode?: string;
275
+ keyword?: string;
276
+ } & PageParams>): Promise<PageInfo<GoodsItem>>;
263
277
  }
@@ -12,3 +12,54 @@ export interface SpecDescription {
12
12
  /** JSON格式的额外属性 */
13
13
  props?: Record<string, string>;
14
14
  }
15
+ /** 商品图片 */
16
+ export interface GoodsImage {
17
+ id?: string;
18
+ url?: string;
19
+ alt?: string;
20
+ sort?: number;
21
+ }
22
+ /** 商品视频 */
23
+ export interface GoodsVideo {
24
+ id?: string;
25
+ url?: string;
26
+ poster?: string;
27
+ }
28
+ /** 商品基础信息(用于列表展示) */
29
+ export interface GoodsItem {
30
+ id: string;
31
+ code: string;
32
+ name: string;
33
+ unitCode: string;
34
+ salePrice: number;
35
+ marketPrice: number;
36
+ description?: string;
37
+ images?: Array<GoodsImage>;
38
+ video?: GoodsVideo;
39
+ tags?: string;
40
+ hidden?: boolean;
41
+ createTime?: string;
42
+ lastUpdateTime?: string;
43
+ /** 货架编码 */
44
+ cateCode?: string;
45
+ /** 货架名称(后端 Transient 填充) */
46
+ cateName?: string;
47
+ }
48
+ /** 货架(商品类目) */
49
+ export interface GoodsCategory {
50
+ id: string;
51
+ /** 货架编码,格式 000-000-000-000-000 */
52
+ code: string;
53
+ name: string;
54
+ description?: string;
55
+ sortValue?: string;
56
+ /** 是否为叶子节点 */
57
+ leaf?: boolean;
58
+ }
59
+ /** 商品标签 */
60
+ export interface GoodsTag {
61
+ id: string;
62
+ code: string;
63
+ name: string;
64
+ websiteNo?: string;
65
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "icms-api",
3
3
  "private": false,
4
- "version": "0.1.3",
4
+ "version": "0.1.5",
5
5
  "description": "对iCMS内容管理系统API的封装,使用该API能快速使用iCMS搭建您的WebApp!",
6
6
  "type": "module",
7
7
  "main": "./dist/icms-api.cjs.js",