@etsoo/smarterp-core 1.0.85 → 1.0.87

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,39 @@
1
+ import { CoreUtils } from "../src";
2
+
3
+ test("Test for validateJson with string schema", async () => {
4
+ const schema =
5
+ '{"type":"object","properties":{"cc":{"type":"array","format":"email","uniqueItems":true},"bcc":{"type":"array","format":"email","uniqueItems":true}}}';
6
+
7
+ let [valid, errors] = await CoreUtils.validateJson(schema, "{}");
8
+ expect(valid).toBeTruthy();
9
+
10
+ [valid, errors] = await CoreUtils.validateJson(schema, {
11
+ cc: ["a@b.com", "a@b.com"]
12
+ });
13
+ expect(valid).toBeFalsy();
14
+ expect(errors?.[0].keyword).toBe("uniqueItems");
15
+ });
16
+
17
+ test("Test for validateJson with object schema", async () => {
18
+ const schema = {
19
+ type: "object",
20
+ properties: {
21
+ cc: {
22
+ type: "array",
23
+ format: "email",
24
+ uniqueItems: true
25
+ },
26
+ bcc: {
27
+ type: "array",
28
+ format: "email",
29
+ uniqueItems: true
30
+ }
31
+ }
32
+ };
33
+
34
+ let [valid, errors] = await CoreUtils.validateJson(schema, {
35
+ cc: "abc"
36
+ });
37
+ expect(valid).toBeFalsy();
38
+ expect(errors?.[0].keyword).toBe("format");
39
+ });
@@ -1,11 +1,24 @@
1
+ import type { ErrorObject } from "ajv";
1
2
  /**
2
3
  * Core utilities
3
4
  */
4
5
  export declare namespace CoreUtils {
5
6
  /**
6
7
  * Get avatar styles
8
+ * 获取头像样式
7
9
  * @param isOrg Is this an organization avatar?
8
10
  * @returns Styles
9
11
  */
10
12
  function avatarStyles(isOrg?: boolean): React.CSSProperties;
13
+ /**
14
+ * Validate JSON input against a schema
15
+ * 验证 JSON 输入是否符合架构
16
+ * @param schema JSON schema to validate against
17
+ * @param input JSON input to validate
18
+ * @returns Result
19
+ */
20
+ function validateJson(schema: string | object, input: string | object | null | undefined): Promise<[
21
+ boolean,
22
+ ErrorObject<string, Record<string, any>, unknown>[] | null | undefined
23
+ ]>;
11
24
  }
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.CoreUtils = void 0;
7
+ const ajv_formats_1 = __importDefault(require("ajv-formats"));
4
8
  /**
5
9
  * Core utilities
6
10
  */
@@ -8,6 +12,7 @@ var CoreUtils;
8
12
  (function (CoreUtils) {
9
13
  /**
10
14
  * Get avatar styles
15
+ * 获取头像样式
11
16
  * @param isOrg Is this an organization avatar?
12
17
  * @returns Styles
13
18
  */
@@ -19,4 +24,27 @@ var CoreUtils;
19
24
  };
20
25
  }
21
26
  CoreUtils.avatarStyles = avatarStyles;
27
+ let ajv = null;
28
+ /**
29
+ * Validate JSON input against a schema
30
+ * 验证 JSON 输入是否符合架构
31
+ * @param schema JSON schema to validate against
32
+ * @param input JSON input to validate
33
+ * @returns Result
34
+ */
35
+ async function validateJson(schema, input) {
36
+ if (ajv == null) {
37
+ const AjvClass = (await import("ajv")).Ajv;
38
+ ajv = new AjvClass({
39
+ allErrors: true,
40
+ strictTypes: false
41
+ });
42
+ (0, ajv_formats_1.default)(ajv);
43
+ }
44
+ return [
45
+ ajv.validate(typeof schema === "string" ? JSON.parse(schema) : schema, typeof input === "string" ? JSON.parse(input) : input),
46
+ ajv.errors
47
+ ];
48
+ }
49
+ CoreUtils.validateJson = validateJson;
22
50
  })(CoreUtils || (exports.CoreUtils = CoreUtils = {}));
@@ -23,6 +23,7 @@ import { OrgUpdateApiRQ } from "./rq/org/OrgUpdateApiRQ";
23
23
  import { OrgUpdateApiReadDto } from "./dto/org/OrgUpdateApiReadDto";
24
24
  import { OrgQueryApiRQ } from "./rq/org/OrgQueryApiRQ";
25
25
  import { OrgQueryApiData } from "./dto/org/OrgQueryApiData";
26
+ import { CoreApiService } from "./dto/org/CoreApiService";
26
27
  /**
27
28
  * Organization API
28
29
  * 机构接口
@@ -133,6 +134,14 @@ export declare class OrgApi extends EntityApi {
133
134
  * @returns Result
134
135
  */
135
136
  read(id: number, payload?: IApiPayload<OrgReadDto>): Promise<OrgReadDto | undefined>;
137
+ /**
138
+ * Read API schema
139
+ * 读取接口架构
140
+ * @param service API service
141
+ * @param payload Payload
142
+ * @returns Result
143
+ */
144
+ readApiSchema(service: CoreApiService, payload?: IApiPayload<object>): Promise<object | undefined>;
136
145
  /**
137
146
  * Get Antiforgery request token
138
147
  * 获取反伪造请求令牌
package/lib/cjs/OrgApi.js CHANGED
@@ -154,6 +154,16 @@ class OrgApi extends appscript_1.EntityApi {
154
154
  read(id, payload) {
155
155
  return this.readBase(id, payload);
156
156
  }
157
+ /**
158
+ * Read API schema
159
+ * 读取接口架构
160
+ * @param service API service
161
+ * @param payload Payload
162
+ * @returns Result
163
+ */
164
+ readApiSchema(service, payload) {
165
+ return this.api.get(`${this.flag}/ReadApiSchema/${service}`, undefined, payload);
166
+ }
157
167
  /**
158
168
  * Get Antiforgery request token
159
169
  * 获取反伪造请求令牌
@@ -1,11 +1,24 @@
1
+ import type { ErrorObject } from "ajv";
1
2
  /**
2
3
  * Core utilities
3
4
  */
4
5
  export declare namespace CoreUtils {
5
6
  /**
6
7
  * Get avatar styles
8
+ * 获取头像样式
7
9
  * @param isOrg Is this an organization avatar?
8
10
  * @returns Styles
9
11
  */
10
12
  function avatarStyles(isOrg?: boolean): React.CSSProperties;
13
+ /**
14
+ * Validate JSON input against a schema
15
+ * 验证 JSON 输入是否符合架构
16
+ * @param schema JSON schema to validate against
17
+ * @param input JSON input to validate
18
+ * @returns Result
19
+ */
20
+ function validateJson(schema: string | object, input: string | object | null | undefined): Promise<[
21
+ boolean,
22
+ ErrorObject<string, Record<string, any>, unknown>[] | null | undefined
23
+ ]>;
11
24
  }
@@ -1,3 +1,4 @@
1
+ import addFormats from "ajv-formats";
1
2
  /**
2
3
  * Core utilities
3
4
  */
@@ -5,6 +6,7 @@ export var CoreUtils;
5
6
  (function (CoreUtils) {
6
7
  /**
7
8
  * Get avatar styles
9
+ * 获取头像样式
8
10
  * @param isOrg Is this an organization avatar?
9
11
  * @returns Styles
10
12
  */
@@ -16,4 +18,27 @@ export var CoreUtils;
16
18
  };
17
19
  }
18
20
  CoreUtils.avatarStyles = avatarStyles;
21
+ let ajv = null;
22
+ /**
23
+ * Validate JSON input against a schema
24
+ * 验证 JSON 输入是否符合架构
25
+ * @param schema JSON schema to validate against
26
+ * @param input JSON input to validate
27
+ * @returns Result
28
+ */
29
+ async function validateJson(schema, input) {
30
+ if (ajv == null) {
31
+ const AjvClass = (await import("ajv")).Ajv;
32
+ ajv = new AjvClass({
33
+ allErrors: true,
34
+ strictTypes: false
35
+ });
36
+ addFormats(ajv);
37
+ }
38
+ return [
39
+ ajv.validate(typeof schema === "string" ? JSON.parse(schema) : schema, typeof input === "string" ? JSON.parse(input) : input),
40
+ ajv.errors
41
+ ];
42
+ }
43
+ CoreUtils.validateJson = validateJson;
19
44
  })(CoreUtils || (CoreUtils = {}));
@@ -23,6 +23,7 @@ import { OrgUpdateApiRQ } from "./rq/org/OrgUpdateApiRQ";
23
23
  import { OrgUpdateApiReadDto } from "./dto/org/OrgUpdateApiReadDto";
24
24
  import { OrgQueryApiRQ } from "./rq/org/OrgQueryApiRQ";
25
25
  import { OrgQueryApiData } from "./dto/org/OrgQueryApiData";
26
+ import { CoreApiService } from "./dto/org/CoreApiService";
26
27
  /**
27
28
  * Organization API
28
29
  * 机构接口
@@ -133,6 +134,14 @@ export declare class OrgApi extends EntityApi {
133
134
  * @returns Result
134
135
  */
135
136
  read(id: number, payload?: IApiPayload<OrgReadDto>): Promise<OrgReadDto | undefined>;
137
+ /**
138
+ * Read API schema
139
+ * 读取接口架构
140
+ * @param service API service
141
+ * @param payload Payload
142
+ * @returns Result
143
+ */
144
+ readApiSchema(service: CoreApiService, payload?: IApiPayload<object>): Promise<object | undefined>;
136
145
  /**
137
146
  * Get Antiforgery request token
138
147
  * 获取反伪造请求令牌
package/lib/mjs/OrgApi.js CHANGED
@@ -151,6 +151,16 @@ export class OrgApi extends EntityApi {
151
151
  read(id, payload) {
152
152
  return this.readBase(id, payload);
153
153
  }
154
+ /**
155
+ * Read API schema
156
+ * 读取接口架构
157
+ * @param service API service
158
+ * @param payload Payload
159
+ * @returns Result
160
+ */
161
+ readApiSchema(service, payload) {
162
+ return this.api.get(`${this.flag}/ReadApiSchema/${service}`, undefined, payload);
163
+ }
154
164
  /**
155
165
  * Get Antiforgery request token
156
166
  * 获取反伪造请求令牌
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/smarterp-core",
3
- "version": "1.0.85",
3
+ "version": "1.0.87",
4
4
  "description": "TypeScript APIs for SmartERP Core",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -40,11 +40,11 @@
40
40
  "license": "MIT",
41
41
  "homepage": "https://github.com/ETSOO/etsoo-smarterp-core#readme",
42
42
  "devDependencies": {
43
- "@babel/cli": "^7.27.2",
44
- "@babel/core": "^7.27.4",
45
- "@babel/plugin-transform-runtime": "^7.27.4",
46
- "@babel/preset-env": "^7.27.2",
47
- "@babel/runtime-corejs3": "^7.27.6",
43
+ "@babel/cli": "^7.28.0",
44
+ "@babel/core": "^7.28.0",
45
+ "@babel/plugin-transform-runtime": "^7.28.0",
46
+ "@babel/preset-env": "^7.28.0",
47
+ "@babel/runtime-corejs3": "^7.28.0",
48
48
  "@types/react": "^18.3.23",
49
49
  "@types/react-dom": "^18.3.7",
50
50
  "@vitejs/plugin-react": "^4.6.0",
@@ -54,11 +54,13 @@
54
54
  },
55
55
  "dependencies": {
56
56
  "@etsoo/appscript": "^1.6.41",
57
- "@etsoo/materialui": "^1.5.63",
57
+ "@etsoo/materialui": "^1.5.64",
58
58
  "@etsoo/react": "^1.8.49",
59
59
  "@etsoo/shared": "^1.2.75",
60
60
  "@etsoo/toolpad": "^1.0.40",
61
- "@mui/material": "^7.1.2",
61
+ "@mui/material": "^7.2.0",
62
+ "ajv": "^8.17.1",
63
+ "ajv-formats": "^3.0.1",
62
64
  "react": "^18.3.1",
63
65
  "react-dom": "^18.3.1"
64
66
  }
package/src/CoreUtils.ts CHANGED
@@ -1,9 +1,14 @@
1
+ import type Ajv from "ajv";
2
+ import type { ErrorObject } from "ajv";
3
+ import addFormats from "ajv-formats";
4
+
1
5
  /**
2
6
  * Core utilities
3
7
  */
4
8
  export namespace CoreUtils {
5
9
  /**
6
10
  * Get avatar styles
11
+ * 获取头像样式
7
12
  * @param isOrg Is this an organization avatar?
8
13
  * @returns Styles
9
14
  */
@@ -14,4 +19,42 @@ export namespace CoreUtils {
14
19
  border: "1px solid #666"
15
20
  };
16
21
  }
22
+
23
+ let ajv: Ajv | null = null;
24
+
25
+ /**
26
+ * Validate JSON input against a schema
27
+ * 验证 JSON 输入是否符合架构
28
+ * @param schema JSON schema to validate against
29
+ * @param input JSON input to validate
30
+ * @returns Result
31
+ */
32
+ export async function validateJson(
33
+ schema: string | object,
34
+ input: string | object | null | undefined
35
+ ): Promise<
36
+ [
37
+ boolean,
38
+ ErrorObject<string, Record<string, any>, unknown>[] | null | undefined
39
+ ]
40
+ > {
41
+ if (ajv == null) {
42
+ const AjvClass = (await import("ajv")).Ajv;
43
+
44
+ ajv = new AjvClass({
45
+ allErrors: true,
46
+ strictTypes: false
47
+ });
48
+
49
+ addFormats(ajv);
50
+ }
51
+
52
+ return [
53
+ ajv!.validate(
54
+ typeof schema === "string" ? JSON.parse(schema) : schema,
55
+ typeof input === "string" ? JSON.parse(input) : input
56
+ ),
57
+ ajv!.errors
58
+ ];
59
+ }
17
60
  }
package/src/OrgApi.ts CHANGED
@@ -32,6 +32,7 @@ import { OrgUpdateApiRQ } from "./rq/org/OrgUpdateApiRQ";
32
32
  import { OrgUpdateApiReadDto } from "./dto/org/OrgUpdateApiReadDto";
33
33
  import { OrgQueryApiRQ } from "./rq/org/OrgQueryApiRQ";
34
34
  import { OrgQueryApiData } from "./dto/org/OrgQueryApiData";
35
+ import { CoreApiService } from "./dto/org/CoreApiService";
35
36
 
36
37
  /**
37
38
  * Organization API
@@ -213,6 +214,21 @@ export class OrgApi extends EntityApi {
213
214
  return this.readBase(id, payload);
214
215
  }
215
216
 
217
+ /**
218
+ * Read API schema
219
+ * 读取接口架构
220
+ * @param service API service
221
+ * @param payload Payload
222
+ * @returns Result
223
+ */
224
+ readApiSchema(service: CoreApiService, payload?: IApiPayload<object>) {
225
+ return this.api.get(
226
+ `${this.flag}/ReadApiSchema/${service}`,
227
+ undefined,
228
+ payload
229
+ );
230
+ }
231
+
216
232
  /**
217
233
  * Get Antiforgery request token
218
234
  * 获取反伪造请求令牌