@handaotech-design/bom 0.0.50 → 0.0.52

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.
Files changed (45) hide show
  1. package/dist/es/components/bom-tree/index.vue +1 -1
  2. package/dist/es/hooks/use-ppboms.d.ts +3 -5
  3. package/dist/es/hooks/use-ppboms.js +44 -42
  4. package/dist/es/index.d.ts +0 -1
  5. package/dist/es/index.js +0 -1
  6. package/dist/es/models/bom.d.ts +23 -0
  7. package/dist/es/models/bom.js +5 -0
  8. package/dist/es/models/common.d.ts +6 -0
  9. package/dist/es/utils/api.d.ts +5 -0
  10. package/dist/es/utils/api.js +10 -0
  11. package/dist/es/utils/child-loader.d.ts +2 -8
  12. package/dist/es/utils/child-loader.js +4 -3
  13. package/dist/es/utils/http-client.d.ts +14 -0
  14. package/dist/es/utils/http-client.js +47 -0
  15. package/dist/es/utils/index.d.ts +1 -1
  16. package/dist/es/utils/index.js +1 -1
  17. package/dist/lib/components/bom-tree/index.vue +1 -1
  18. package/dist/lib/hooks/use-ppboms.d.ts +3 -5
  19. package/dist/lib/hooks/use-ppboms.js +49 -42
  20. package/dist/lib/index.d.ts +0 -1
  21. package/dist/lib/index.js +0 -12
  22. package/dist/lib/models/bom.d.ts +23 -0
  23. package/dist/lib/models/bom.js +7 -2
  24. package/dist/lib/models/common.d.ts +6 -0
  25. package/dist/lib/utils/api.d.ts +5 -0
  26. package/dist/lib/utils/api.js +16 -0
  27. package/dist/lib/utils/child-loader.d.ts +2 -8
  28. package/dist/lib/utils/child-loader.js +4 -3
  29. package/dist/lib/utils/http-client.d.ts +14 -0
  30. package/dist/lib/utils/http-client.js +52 -0
  31. package/dist/lib/utils/index.d.ts +1 -1
  32. package/dist/lib/utils/index.js +4 -4
  33. package/package.json +1 -1
  34. package/dist/es/models/http-client.d.ts +0 -4
  35. package/dist/es/models/http-client.js +0 -0
  36. package/dist/es/sdk/index.d.ts +0 -11
  37. package/dist/es/sdk/index.js +0 -34
  38. package/dist/es/utils/config.d.ts +0 -1
  39. package/dist/es/utils/config.js +0 -11
  40. package/dist/lib/models/http-client.d.ts +0 -4
  41. package/dist/lib/models/http-client.js +0 -1
  42. package/dist/lib/sdk/index.d.ts +0 -11
  43. package/dist/lib/sdk/index.js +0 -43
  44. package/dist/lib/utils/config.d.ts +0 -1
  45. package/dist/lib/utils/config.js +0 -18
@@ -332,7 +332,7 @@ async function _loadData(node: EventDataNode) {
332
332
  <a-tree
333
333
  ref="treeRef"
334
334
  :height="treeContainerHeight"
335
- :tree-data="displayTreeData"
335
+ :tree-data="displayTreeData as any"
336
336
  :expanded-keys="expandedKeys"
337
337
  :auto-expand-parent="autoExpandParent"
338
338
  :block-node="true"
@@ -1,12 +1,9 @@
1
- export declare enum QueryType {
2
- ALL = "ALL",
3
- MODEL_ESN = "MODEL_ESN"
4
- }
1
+ import type { BomNode } from '../models';
5
2
  interface UsePpbomsParams {
6
3
  host: string;
7
4
  appId: string;
8
5
  appSecret: string;
9
- queryType?: QueryType;
6
+ configCode?: string;
10
7
  options?: Record<string, any>;
11
8
  }
12
9
  export declare const usePpboms: (params: UsePpbomsParams) => {
@@ -15,5 +12,6 @@ export declare const usePpboms: (params: UsePpbomsParams) => {
15
12
  treeConfig: import("vue").Ref<any>;
16
13
  loading: import("vue").Ref<boolean>;
17
14
  getDataAndConfig: () => Promise<void>;
15
+ loadChildren: (bomNode: BomNode) => Promise<BomNode[]>;
18
16
  };
19
17
  export {};
@@ -1,81 +1,83 @@
1
1
  import { ref } from "vue";
2
- import { convertBomDataToTree, getConfig } from "../utils/index.js";
3
- import { YesNo } from "../models/index.js";
4
- const ppbomPageConfigCode = "PPBOM_PAGE";
5
- export var QueryType = /* @__PURE__ */ ((QueryType2) => {
6
- QueryType2["ALL"] = "ALL";
7
- QueryType2["MODEL_ESN"] = "MODEL_ESN";
8
- return QueryType2;
9
- })(QueryType || {});
2
+ import { HttpClient } from "../utils/http-client.js";
3
+ import { BomFetcherType } from "../models/index.js";
4
+ import { RuleEngine, api } from "../utils/index.js";
5
+ import { ChildLoadersManager } from "../utils/child-loader.js";
6
+ const DEFAULT_PPBOM_PAGE_CONFIG_CODE = "PPBOM_PAGE";
10
7
  export const usePpboms = (params) => {
11
- const { host, appId, appSecret, queryType, options } = params;
8
+ const { host, appId, appSecret, configCode, options } = params;
12
9
  const loading = ref(false);
13
10
  const treeData = ref();
14
11
  const treeConfig = ref();
15
12
  const layoutConfig = ref();
13
+ const pageConfigCode = configCode ?? DEFAULT_PPBOM_PAGE_CONFIG_CODE;
14
+ const httpClient = new HttpClient({
15
+ baseURL: host,
16
+ defaultHeaders: {
17
+ "Content-Type": "application/json",
18
+ "X-CONSUMER-ID": appId,
19
+ "Authorization": `Bearer ${appSecret}`
20
+ }
21
+ });
16
22
  const queryBoms = async () => {
17
23
  const body = {
18
24
  page: 1,
19
25
  pageSize: Number.MAX_SAFE_INTEGER,
20
26
  ...options ?? {}
21
27
  };
22
- const response = await fetch(`http://${host}/api/public/v2/ppboms/query/all`, {
23
- method: "POST",
24
- headers: {
25
- "Content-Type": "application/json",
26
- "X-CONSUMER-ID": appId,
27
- "Authorization": `Bearer ${appSecret}`
28
- },
29
- body: JSON.stringify(body)
30
- });
31
- return response.json();
28
+ const response = await httpClient.post("/api/public/v2/ppboms/query/all", body);
29
+ return response.data;
32
30
  };
33
- const queryBomsByModelEsn = async () => {
31
+ const queryBomsLazy = async () => {
34
32
  const body = {
35
33
  page: 1,
36
34
  pageSize: Number.MAX_SAFE_INTEGER,
37
- forceSettle: YesNo.YES,
38
- lookupOnly: YesNo.YES,
39
35
  ...options ?? {}
40
36
  };
41
- const response = await fetch(`http://${host}/api/public/v2/ppboms/query/by-model-esn`, {
42
- method: "POST",
43
- headers: {
44
- "Content-Type": "application/json",
45
- "X-CONSUMER-ID": appId,
46
- "Authorization": `Bearer ${appSecret}`
47
- },
48
- body: JSON.stringify(body)
49
- });
50
- return response.json();
37
+ const response = await httpClient.post("/api/public/v2/ppboms/query/lazy-all", body);
38
+ return response.data;
51
39
  };
52
- const getData = async () => {
40
+ const getData = async (queryType) => {
53
41
  switch (queryType) {
54
- case "MODEL_ESN" /* MODEL_ESN */:
55
- return await queryBomsByModelEsn();
56
- default:
42
+ case BomFetcherType.PPBOM_ALL:
57
43
  return await queryBoms();
44
+ case BomFetcherType.PPBOM_LAZY_ALL:
45
+ return await queryBomsLazy();
46
+ default:
47
+ return { items: [], total: 0 };
58
48
  }
59
49
  };
60
50
  const getDataAndConfig = async () => {
61
51
  try {
62
52
  loading.value = true;
63
- const dataResp = await getData();
64
- const configResp = await getConfig(host, ppbomPageConfigCode, appId, appSecret);
65
- loading.value = false;
53
+ const configResp = await api.getConfig(pageConfigCode, httpClient);
66
54
  const props = configResp.config.props;
67
- treeData.value = convertBomDataToTree(dataResp.data.items, props.content.tree.nodeConfig.rule);
68
55
  treeConfig.value = props.content.tree;
69
- layoutConfig.value = props.content.tree.layout;
56
+ layoutConfig.value = props.content.layout;
57
+ const dataResp = await getData(props.bomFetcher.type);
58
+ treeData.value = dataResp.items;
59
+ loading.value = false;
70
60
  } finally {
71
61
  loading.value = false;
72
62
  }
73
63
  };
64
+ const loadChildren = async (bomNode) => {
65
+ const ruleEngine = new RuleEngine(treeConfig.value.nodeConfig.rule);
66
+ const matched = ruleEngine.matchOne({ bomNode });
67
+ if (matched?.childrenLoader) {
68
+ const loader = ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
69
+ if (loader) {
70
+ return await loader(bomNode, httpClient);
71
+ }
72
+ }
73
+ return [];
74
+ };
74
75
  return {
75
76
  treeData,
76
77
  layoutConfig,
77
78
  treeConfig,
78
79
  loading,
79
- getDataAndConfig
80
+ getDataAndConfig,
81
+ loadChildren
80
82
  };
81
83
  };
@@ -3,6 +3,5 @@ export * from './components';
3
3
  export * from './hooks';
4
4
  export * from './models';
5
5
  export * from './utils';
6
- export * from './sdk';
7
6
  export declare const install: (app: import("vue").App) => void;
8
7
  export default installer;
package/dist/es/index.js CHANGED
@@ -3,6 +3,5 @@ export * from "./components/index.js";
3
3
  export * from "./hooks/index.js";
4
4
  export * from "./models/index.js";
5
5
  export * from "./utils/index.js";
6
- export * from "./sdk/index.js";
7
6
  export const install = installer.install;
8
7
  export default installer;
@@ -49,3 +49,26 @@ export interface BomNode {
49
49
  raw: Record<string, any>;
50
50
  [key: string]: any;
51
51
  }
52
+ export interface BomNodeDetails {
53
+ component: any;
54
+ }
55
+ export interface PageLayoutConfig {
56
+ maxLeftWidth: number;
57
+ }
58
+ export interface BomContentConfig {
59
+ layout?: PageLayoutConfig;
60
+ tree: BomTreeConfig;
61
+ nodeDetails: BomNodeDetails;
62
+ }
63
+ export declare enum BomFetcherType {
64
+ PPBOM_LAZY_ALL = "ppbomLazyAll",
65
+ PPBOM_ALL = "ppbomAll"
66
+ }
67
+ export interface BomFetcherConfig {
68
+ type: BomFetcherType;
69
+ }
70
+ export interface BomPageConfig {
71
+ bomType: string;
72
+ bomFetcher: BomFetcherConfig;
73
+ content: BomContentConfig;
74
+ }
@@ -1 +1,6 @@
1
1
  export const defaultTitleTemplate = "${code}";
2
+ export var BomFetcherType = /* @__PURE__ */ ((BomFetcherType2) => {
3
+ BomFetcherType2["PPBOM_LAZY_ALL"] = "ppbomLazyAll";
4
+ BomFetcherType2["PPBOM_ALL"] = "ppbomAll";
5
+ return BomFetcherType2;
6
+ })(BomFetcherType || {});
@@ -3,3 +3,9 @@ export declare enum YesNo {
3
3
  NO = "NO"
4
4
  }
5
5
  export type Optional<T> = T | undefined | null;
6
+ export interface HttpResponse<T> {
7
+ code: number;
8
+ message: string;
9
+ data: T;
10
+ detail?: any;
11
+ }
@@ -0,0 +1,5 @@
1
+ import type { HttpClient } from './http-client';
2
+ export declare const api: {
3
+ getConfig: <T>(code: string, httpClient: HttpClient) => Promise<T>;
4
+ getBusinessId: <T>(bomNodeId: string, httpClient: HttpClient) => Promise<T>;
5
+ };
@@ -0,0 +1,10 @@
1
+ const getConfig = async (code, httpClient) => {
2
+ return httpClient.get(`/api/public/v2/business-configs/${code}`);
3
+ };
4
+ const getBusinessId = async (bomNodeId, httpClient) => {
5
+ return httpClient.get(`/api/public/v2/ppboms/nodes/${bomNodeId}/business`);
6
+ };
7
+ export const api = {
8
+ getConfig,
9
+ getBusinessId
10
+ };
@@ -1,12 +1,6 @@
1
1
  import type { BomNode } from '../models';
2
- export interface IPartialBomSDK {
3
- httpClient: any;
4
- getBusinessId(bomNodeId: string): Promise<any>;
5
- getBusinessConfig(configCode: string): Promise<any>;
6
- getOperations(processPlanId: string): Promise<any>;
7
- }
8
- export type ChildLoaderFn = (bomNode: BomNode, sdk: IPartialBomSDK) => Promise<BomNode[]>;
9
- export declare function getOperationNodes(bomNode: BomNode, sdk: IPartialBomSDK): Promise<BomNode[]>;
2
+ import type { HttpClient } from './http-client';
3
+ export declare function getOperationNodes(bomNode: BomNode, httpClient: HttpClient): Promise<BomNode[]>;
10
4
  export declare namespace getOperationNodes {
11
5
  var type: string;
12
6
  }
@@ -1,6 +1,7 @@
1
- export async function getOperationNodes(bomNode, sdk) {
2
- const { data: processPlanId } = await sdk.getBusinessId(bomNode.id);
3
- const response = await sdk.getOperations(processPlanId);
1
+ import { api } from "./api.js";
2
+ export async function getOperationNodes(bomNode, httpClient) {
3
+ const { data: processPlanId } = await api.getBusinessId(bomNode.id, httpClient);
4
+ const response = await httpClient.get(`/api/public/v2/process-plans/${processPlanId}/operations`);
4
5
  return (response.data || []).map((op) => {
5
6
  return {
6
7
  id: op.id,
@@ -0,0 +1,14 @@
1
+ export interface HttpClientOptions {
2
+ baseURL: string;
3
+ defaultHeaders?: Record<string, string>;
4
+ authProvider?: () => string | Promise<string>;
5
+ }
6
+ export declare class HttpClient {
7
+ private readonly baseURL;
8
+ private readonly defaultHeaders;
9
+ private readonly authProvider?;
10
+ constructor(options: HttpClientOptions);
11
+ get<T>(url: string, config?: RequestInit): Promise<T>;
12
+ post<T>(url: string, data?: any, config?: RequestInit): Promise<T>;
13
+ private request;
14
+ }
@@ -0,0 +1,47 @@
1
+ export class HttpClient {
2
+ baseURL;
3
+ defaultHeaders;
4
+ authProvider;
5
+ constructor(options) {
6
+ this.baseURL = options.baseURL;
7
+ this.defaultHeaders = options.defaultHeaders || {};
8
+ this.authProvider = options.authProvider;
9
+ }
10
+ async get(url, config) {
11
+ return this.request(url, {
12
+ method: "GET",
13
+ ...config
14
+ });
15
+ }
16
+ async post(url, data, config) {
17
+ return this.request(url, {
18
+ method: "POST",
19
+ body: data !== void 0 ? JSON.stringify(data) : void 0,
20
+ ...config
21
+ });
22
+ }
23
+ async request(url, init) {
24
+ const headers = {
25
+ "Content-Type": "application/json",
26
+ ...this.defaultHeaders,
27
+ ...init.headers
28
+ };
29
+ if (this.authProvider) {
30
+ const token = await this.authProvider();
31
+ if (token) {
32
+ headers.Authorization = `Bearer ${token}`;
33
+ }
34
+ }
35
+ const response = await fetch(`${this.baseURL}${url}`, {
36
+ ...init,
37
+ headers
38
+ });
39
+ if (!response.ok) {
40
+ const text = await response.text();
41
+ throw new Error(
42
+ `[Bom Component] HTTP ${response.status} ${response.statusText}: ${text}`
43
+ );
44
+ }
45
+ return response.json();
46
+ }
47
+ }
@@ -1,4 +1,4 @@
1
1
  export * from './bom';
2
2
  export * from './rule-engine';
3
3
  export * from './template';
4
- export * from './config';
4
+ export * from './api';
@@ -1,4 +1,4 @@
1
1
  export * from "./bom.js";
2
2
  export * from "./rule-engine.js";
3
3
  export * from "./template.js";
4
- export * from "./config.js";
4
+ export * from "./api.js";
@@ -332,7 +332,7 @@ async function _loadData(node: EventDataNode) {
332
332
  <a-tree
333
333
  ref="treeRef"
334
334
  :height="treeContainerHeight"
335
- :tree-data="displayTreeData"
335
+ :tree-data="displayTreeData as any"
336
336
  :expanded-keys="expandedKeys"
337
337
  :auto-expand-parent="autoExpandParent"
338
338
  :block-node="true"
@@ -1,12 +1,9 @@
1
- export declare enum QueryType {
2
- ALL = "ALL",
3
- MODEL_ESN = "MODEL_ESN"
4
- }
1
+ import type { BomNode } from '../models';
5
2
  interface UsePpbomsParams {
6
3
  host: string;
7
4
  appId: string;
8
5
  appSecret: string;
9
- queryType?: QueryType;
6
+ configCode?: string;
10
7
  options?: Record<string, any>;
11
8
  }
12
9
  export declare const usePpboms: (params: UsePpbomsParams) => {
@@ -15,5 +12,6 @@ export declare const usePpboms: (params: UsePpbomsParams) => {
15
12
  treeConfig: import("vue").Ref<any>;
16
13
  loading: import("vue").Ref<boolean>;
17
14
  getDataAndConfig: () => Promise<void>;
15
+ loadChildren: (bomNode: BomNode) => Promise<BomNode[]>;
18
16
  };
19
17
  export {};
@@ -3,92 +3,99 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.usePpboms = exports.QueryType = void 0;
6
+ exports.usePpboms = void 0;
7
7
  var _vue = require("vue");
8
- var _utils = require("../utils");
8
+ var _httpClient = require("../utils/http-client");
9
9
  var _models = require("../models");
10
- const ppbomPageConfigCode = "PPBOM_PAGE";
11
- var QueryType = exports.QueryType = /* @__PURE__ */(QueryType2 => {
12
- QueryType2["ALL"] = "ALL";
13
- QueryType2["MODEL_ESN"] = "MODEL_ESN";
14
- return QueryType2;
15
- })(QueryType || {});
10
+ var _utils = require("../utils");
11
+ var _childLoader = require("../utils/child-loader");
12
+ const DEFAULT_PPBOM_PAGE_CONFIG_CODE = "PPBOM_PAGE";
16
13
  const usePpboms = params => {
17
14
  const {
18
15
  host,
19
16
  appId,
20
17
  appSecret,
21
- queryType,
18
+ configCode,
22
19
  options
23
20
  } = params;
24
21
  const loading = (0, _vue.ref)(false);
25
22
  const treeData = (0, _vue.ref)();
26
23
  const treeConfig = (0, _vue.ref)();
27
24
  const layoutConfig = (0, _vue.ref)();
25
+ const pageConfigCode = configCode ?? DEFAULT_PPBOM_PAGE_CONFIG_CODE;
26
+ const httpClient = new _httpClient.HttpClient({
27
+ baseURL: host,
28
+ defaultHeaders: {
29
+ "Content-Type": "application/json",
30
+ "X-CONSUMER-ID": appId,
31
+ "Authorization": `Bearer ${appSecret}`
32
+ }
33
+ });
28
34
  const queryBoms = async () => {
29
35
  const body = {
30
36
  page: 1,
31
37
  pageSize: Number.MAX_SAFE_INTEGER,
32
38
  ...(options ?? {})
33
39
  };
34
- const response = await fetch(`http://${host}/api/public/v2/ppboms/query/all`, {
35
- method: "POST",
36
- headers: {
37
- "Content-Type": "application/json",
38
- "X-CONSUMER-ID": appId,
39
- "Authorization": `Bearer ${appSecret}`
40
- },
41
- body: JSON.stringify(body)
42
- });
43
- return response.json();
40
+ const response = await httpClient.post("/api/public/v2/ppboms/query/all", body);
41
+ return response.data;
44
42
  };
45
- const queryBomsByModelEsn = async () => {
43
+ const queryBomsLazy = async () => {
46
44
  const body = {
47
45
  page: 1,
48
46
  pageSize: Number.MAX_SAFE_INTEGER,
49
- forceSettle: _models.YesNo.YES,
50
- lookupOnly: _models.YesNo.YES,
51
47
  ...(options ?? {})
52
48
  };
53
- const response = await fetch(`http://${host}/api/public/v2/ppboms/query/by-model-esn`, {
54
- method: "POST",
55
- headers: {
56
- "Content-Type": "application/json",
57
- "X-CONSUMER-ID": appId,
58
- "Authorization": `Bearer ${appSecret}`
59
- },
60
- body: JSON.stringify(body)
61
- });
62
- return response.json();
49
+ const response = await httpClient.post("/api/public/v2/ppboms/query/lazy-all", body);
50
+ return response.data;
63
51
  };
64
- const getData = async () => {
52
+ const getData = async queryType => {
65
53
  switch (queryType) {
66
- case "MODEL_ESN" /* MODEL_ESN */:
67
- return await queryBomsByModelEsn();
68
- default:
54
+ case _models.BomFetcherType.PPBOM_ALL:
69
55
  return await queryBoms();
56
+ case _models.BomFetcherType.PPBOM_LAZY_ALL:
57
+ return await queryBomsLazy();
58
+ default:
59
+ return {
60
+ items: [],
61
+ total: 0
62
+ };
70
63
  }
71
64
  };
72
65
  const getDataAndConfig = async () => {
73
66
  try {
74
67
  loading.value = true;
75
- const dataResp = await getData();
76
- const configResp = await (0, _utils.getConfig)(host, ppbomPageConfigCode, appId, appSecret);
77
- loading.value = false;
68
+ const configResp = await _utils.api.getConfig(pageConfigCode, httpClient);
78
69
  const props = configResp.config.props;
79
- treeData.value = (0, _utils.convertBomDataToTree)(dataResp.data.items, props.content.tree.nodeConfig.rule);
80
70
  treeConfig.value = props.content.tree;
81
- layoutConfig.value = props.content.tree.layout;
71
+ layoutConfig.value = props.content.layout;
72
+ const dataResp = await getData(props.bomFetcher.type);
73
+ treeData.value = dataResp.items;
74
+ loading.value = false;
82
75
  } finally {
83
76
  loading.value = false;
84
77
  }
85
78
  };
79
+ const loadChildren = async bomNode => {
80
+ const ruleEngine = new _utils.RuleEngine(treeConfig.value.nodeConfig.rule);
81
+ const matched = ruleEngine.matchOne({
82
+ bomNode
83
+ });
84
+ if (matched?.childrenLoader) {
85
+ const loader = _childLoader.ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
86
+ if (loader) {
87
+ return await loader(bomNode, httpClient);
88
+ }
89
+ }
90
+ return [];
91
+ };
86
92
  return {
87
93
  treeData,
88
94
  layoutConfig,
89
95
  treeConfig,
90
96
  loading,
91
- getDataAndConfig
97
+ getDataAndConfig,
98
+ loadChildren
92
99
  };
93
100
  };
94
101
  exports.usePpboms = usePpboms;
@@ -3,6 +3,5 @@ export * from './components';
3
3
  export * from './hooks';
4
4
  export * from './models';
5
5
  export * from './utils';
6
- export * from './sdk';
7
6
  export declare const install: (app: import("vue").App) => void;
8
7
  export default installer;
package/dist/lib/index.js CHANGED
@@ -56,18 +56,6 @@ Object.keys(_utils).forEach(function (key) {
56
56
  }
57
57
  });
58
58
  });
59
- var _sdk = require("./sdk");
60
- Object.keys(_sdk).forEach(function (key) {
61
- if (key === "default" || key === "__esModule") return;
62
- if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
63
- if (key in exports && exports[key] === _sdk[key]) return;
64
- Object.defineProperty(exports, key, {
65
- enumerable: true,
66
- get: function () {
67
- return _sdk[key];
68
- }
69
- });
70
- });
71
59
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
72
60
  const install = exports.install = _defaults.default.install;
73
61
  module.exports = _defaults.default;
@@ -49,3 +49,26 @@ export interface BomNode {
49
49
  raw: Record<string, any>;
50
50
  [key: string]: any;
51
51
  }
52
+ export interface BomNodeDetails {
53
+ component: any;
54
+ }
55
+ export interface PageLayoutConfig {
56
+ maxLeftWidth: number;
57
+ }
58
+ export interface BomContentConfig {
59
+ layout?: PageLayoutConfig;
60
+ tree: BomTreeConfig;
61
+ nodeDetails: BomNodeDetails;
62
+ }
63
+ export declare enum BomFetcherType {
64
+ PPBOM_LAZY_ALL = "ppbomLazyAll",
65
+ PPBOM_ALL = "ppbomAll"
66
+ }
67
+ export interface BomFetcherConfig {
68
+ type: BomFetcherType;
69
+ }
70
+ export interface BomPageConfig {
71
+ bomType: string;
72
+ bomFetcher: BomFetcherConfig;
73
+ content: BomContentConfig;
74
+ }
@@ -3,5 +3,10 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.defaultTitleTemplate = void 0;
7
- const defaultTitleTemplate = exports.defaultTitleTemplate = "${code}";
6
+ exports.defaultTitleTemplate = exports.BomFetcherType = void 0;
7
+ const defaultTitleTemplate = exports.defaultTitleTemplate = "${code}";
8
+ var BomFetcherType = exports.BomFetcherType = /* @__PURE__ */(BomFetcherType2 => {
9
+ BomFetcherType2["PPBOM_LAZY_ALL"] = "ppbomLazyAll";
10
+ BomFetcherType2["PPBOM_ALL"] = "ppbomAll";
11
+ return BomFetcherType2;
12
+ })(BomFetcherType || {});
@@ -3,3 +3,9 @@ export declare enum YesNo {
3
3
  NO = "NO"
4
4
  }
5
5
  export type Optional<T> = T | undefined | null;
6
+ export interface HttpResponse<T> {
7
+ code: number;
8
+ message: string;
9
+ data: T;
10
+ detail?: any;
11
+ }
@@ -0,0 +1,5 @@
1
+ import type { HttpClient } from './http-client';
2
+ export declare const api: {
3
+ getConfig: <T>(code: string, httpClient: HttpClient) => Promise<T>;
4
+ getBusinessId: <T>(bomNodeId: string, httpClient: HttpClient) => Promise<T>;
5
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.api = void 0;
7
+ const getConfig = async (code, httpClient) => {
8
+ return httpClient.get(`/api/public/v2/business-configs/${code}`);
9
+ };
10
+ const getBusinessId = async (bomNodeId, httpClient) => {
11
+ return httpClient.get(`/api/public/v2/ppboms/nodes/${bomNodeId}/business`);
12
+ };
13
+ const api = exports.api = {
14
+ getConfig,
15
+ getBusinessId
16
+ };
@@ -1,12 +1,6 @@
1
1
  import type { BomNode } from '../models';
2
- export interface IPartialBomSDK {
3
- httpClient: any;
4
- getBusinessId(bomNodeId: string): Promise<any>;
5
- getBusinessConfig(configCode: string): Promise<any>;
6
- getOperations(processPlanId: string): Promise<any>;
7
- }
8
- export type ChildLoaderFn = (bomNode: BomNode, sdk: IPartialBomSDK) => Promise<BomNode[]>;
9
- export declare function getOperationNodes(bomNode: BomNode, sdk: IPartialBomSDK): Promise<BomNode[]>;
2
+ import type { HttpClient } from './http-client';
3
+ export declare function getOperationNodes(bomNode: BomNode, httpClient: HttpClient): Promise<BomNode[]>;
10
4
  export declare namespace getOperationNodes {
11
5
  var type: string;
12
6
  }
@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.ChildLoadersManager = void 0;
7
7
  exports.getOperationNodes = getOperationNodes;
8
- async function getOperationNodes(bomNode, sdk) {
8
+ var _api = require("./api");
9
+ async function getOperationNodes(bomNode, httpClient) {
9
10
  const {
10
11
  data: processPlanId
11
- } = await sdk.getBusinessId(bomNode.id);
12
- const response = await sdk.getOperations(processPlanId);
12
+ } = await _api.api.getBusinessId(bomNode.id, httpClient);
13
+ const response = await httpClient.get(`/api/public/v2/process-plans/${processPlanId}/operations`);
13
14
  return (response.data || []).map(op => {
14
15
  return {
15
16
  id: op.id,
@@ -0,0 +1,14 @@
1
+ export interface HttpClientOptions {
2
+ baseURL: string;
3
+ defaultHeaders?: Record<string, string>;
4
+ authProvider?: () => string | Promise<string>;
5
+ }
6
+ export declare class HttpClient {
7
+ private readonly baseURL;
8
+ private readonly defaultHeaders;
9
+ private readonly authProvider?;
10
+ constructor(options: HttpClientOptions);
11
+ get<T>(url: string, config?: RequestInit): Promise<T>;
12
+ post<T>(url: string, data?: any, config?: RequestInit): Promise<T>;
13
+ private request;
14
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.HttpClient = void 0;
7
+ class HttpClient {
8
+ baseURL;
9
+ defaultHeaders;
10
+ authProvider;
11
+ constructor(options) {
12
+ this.baseURL = options.baseURL;
13
+ this.defaultHeaders = options.defaultHeaders || {};
14
+ this.authProvider = options.authProvider;
15
+ }
16
+ async get(url, config) {
17
+ return this.request(url, {
18
+ method: "GET",
19
+ ...config
20
+ });
21
+ }
22
+ async post(url, data, config) {
23
+ return this.request(url, {
24
+ method: "POST",
25
+ body: data !== void 0 ? JSON.stringify(data) : void 0,
26
+ ...config
27
+ });
28
+ }
29
+ async request(url, init) {
30
+ const headers = {
31
+ "Content-Type": "application/json",
32
+ ...this.defaultHeaders,
33
+ ...init.headers
34
+ };
35
+ if (this.authProvider) {
36
+ const token = await this.authProvider();
37
+ if (token) {
38
+ headers.Authorization = `Bearer ${token}`;
39
+ }
40
+ }
41
+ const response = await fetch(`${this.baseURL}${url}`, {
42
+ ...init,
43
+ headers
44
+ });
45
+ if (!response.ok) {
46
+ const text = await response.text();
47
+ throw new Error(`[Bom Component] HTTP ${response.status} ${response.statusText}: ${text}`);
48
+ }
49
+ return response.json();
50
+ }
51
+ }
52
+ exports.HttpClient = HttpClient;
@@ -1,4 +1,4 @@
1
1
  export * from './bom';
2
2
  export * from './rule-engine';
3
3
  export * from './template';
4
- export * from './config';
4
+ export * from './api';
@@ -36,14 +36,14 @@ Object.keys(_template).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
- var _config = require("./config");
40
- Object.keys(_config).forEach(function (key) {
39
+ var _api = require("./api");
40
+ Object.keys(_api).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _config[key]) return;
42
+ if (key in exports && exports[key] === _api[key]) return;
43
43
  Object.defineProperty(exports, key, {
44
44
  enumerable: true,
45
45
  get: function () {
46
- return _config[key];
46
+ return _api[key];
47
47
  }
48
48
  });
49
49
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@handaotech-design/bom",
3
- "version": "0.0.50",
3
+ "version": "0.0.52",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -1,4 +0,0 @@
1
- export interface HttpClient {
2
- get<T>(url: string, config?: any): Promise<T>;
3
- post<T>(url: string, data?: any, config?: any): Promise<T>;
4
- }
File without changes
@@ -1,11 +0,0 @@
1
- import type { HttpClient } from '../models/http-client';
2
- import type { BomNode, BomTreeConfig } from '../models';
3
- export declare class BomSDK {
4
- httpClient: HttpClient;
5
- constructor(client: HttpClient);
6
- lazyLoadAllPpboms(): Promise<unknown>;
7
- getBusinessConfig(configCode: string): Promise<unknown>;
8
- getBusinessId(bomNodeId: string): Promise<unknown>;
9
- loadChildren(bomNode: BomNode, treeConfig: BomTreeConfig): Promise<BomNode[]>;
10
- getOperations(processPlanId: string): Promise<unknown>;
11
- }
@@ -1,34 +0,0 @@
1
- import { RuleEngine } from "../utils/index.js";
2
- import { ChildLoadersManager } from "../utils/child-loader.js";
3
- export class BomSDK {
4
- httpClient;
5
- constructor(client) {
6
- this.httpClient = client;
7
- }
8
- async lazyLoadAllPpboms() {
9
- return this.httpClient.post("/ppboms/query/lazy-all", {
10
- page: 1,
11
- pageSize: Number.MAX_SAFE_INTEGER
12
- });
13
- }
14
- async getBusinessConfig(configCode) {
15
- return this.httpClient.get(`/business-configs/${configCode}`);
16
- }
17
- async getBusinessId(bomNodeId) {
18
- return this.httpClient.get(`/bom-nodes/${bomNodeId}/business`);
19
- }
20
- async loadChildren(bomNode, treeConfig) {
21
- const ruleEngine = new RuleEngine(treeConfig.nodeConfig.rule);
22
- const matched = ruleEngine.matchOne({ bomNode });
23
- if (matched?.childrenLoader) {
24
- const loader = ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
25
- if (loader) {
26
- return await loader(bomNode, this);
27
- }
28
- }
29
- return [];
30
- }
31
- async getOperations(processPlanId) {
32
- return this.httpClient.get(`/process-plans/${processPlanId}/operations`);
33
- }
34
- }
@@ -1 +0,0 @@
1
- export declare const getConfig: (host: string, code: string, appId: string, appSecret: string) => Promise<any>;
@@ -1,11 +0,0 @@
1
- export const getConfig = async (host, code, appId, appSecret) => {
2
- const response = await fetch(`http://${host}/api/public/v2/business-configs/${code}`, {
3
- method: "GET",
4
- headers: {
5
- "Content-Type": "application/json",
6
- "X-CONSUMER-ID": appId,
7
- "Authorization": `Bearer ${appSecret}`
8
- }
9
- });
10
- return await response.json();
11
- };
@@ -1,4 +0,0 @@
1
- export interface HttpClient {
2
- get<T>(url: string, config?: any): Promise<T>;
3
- post<T>(url: string, data?: any, config?: any): Promise<T>;
4
- }
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,11 +0,0 @@
1
- import type { HttpClient } from '../models/http-client';
2
- import type { BomNode, BomTreeConfig } from '../models';
3
- export declare class BomSDK {
4
- httpClient: HttpClient;
5
- constructor(client: HttpClient);
6
- lazyLoadAllPpboms(): Promise<unknown>;
7
- getBusinessConfig(configCode: string): Promise<unknown>;
8
- getBusinessId(bomNodeId: string): Promise<unknown>;
9
- loadChildren(bomNode: BomNode, treeConfig: BomTreeConfig): Promise<BomNode[]>;
10
- getOperations(processPlanId: string): Promise<unknown>;
11
- }
@@ -1,43 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.BomSDK = void 0;
7
- var _utils = require("../utils");
8
- var _childLoader = require("../utils/child-loader");
9
- class BomSDK {
10
- httpClient;
11
- constructor(client) {
12
- this.httpClient = client;
13
- }
14
- async lazyLoadAllPpboms() {
15
- return this.httpClient.post("/ppboms/query/lazy-all", {
16
- page: 1,
17
- pageSize: Number.MAX_SAFE_INTEGER
18
- });
19
- }
20
- async getBusinessConfig(configCode) {
21
- return this.httpClient.get(`/business-configs/${configCode}`);
22
- }
23
- async getBusinessId(bomNodeId) {
24
- return this.httpClient.get(`/bom-nodes/${bomNodeId}/business`);
25
- }
26
- async loadChildren(bomNode, treeConfig) {
27
- const ruleEngine = new _utils.RuleEngine(treeConfig.nodeConfig.rule);
28
- const matched = ruleEngine.matchOne({
29
- bomNode
30
- });
31
- if (matched?.childrenLoader) {
32
- const loader = _childLoader.ChildLoadersManager.getChildLoader(matched?.childrenLoader.type);
33
- if (loader) {
34
- return await loader(bomNode, this);
35
- }
36
- }
37
- return [];
38
- }
39
- async getOperations(processPlanId) {
40
- return this.httpClient.get(`/process-plans/${processPlanId}/operations`);
41
- }
42
- }
43
- exports.BomSDK = BomSDK;
@@ -1 +0,0 @@
1
- export declare const getConfig: (host: string, code: string, appId: string, appSecret: string) => Promise<any>;
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getConfig = void 0;
7
- const getConfig = async (host, code, appId, appSecret) => {
8
- const response = await fetch(`http://${host}/api/public/v2/business-configs/${code}`, {
9
- method: "GET",
10
- headers: {
11
- "Content-Type": "application/json",
12
- "X-CONSUMER-ID": appId,
13
- "Authorization": `Bearer ${appSecret}`
14
- }
15
- });
16
- return await response.json();
17
- };
18
- exports.getConfig = getConfig;