hik-iot-sdk 1.0.0
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/README.md +467 -0
- package/dist/core/__tests__/crypto.test.d.ts +1 -0
- package/dist/core/__tests__/crypto.test.js +68 -0
- package/dist/core/auth.d.ts +51 -0
- package/dist/core/auth.js +292 -0
- package/dist/core/config.d.ts +31 -0
- package/dist/core/config.js +11 -0
- package/dist/core/crypto.d.ts +12 -0
- package/dist/core/crypto.js +88 -0
- package/dist/core/errors.d.ts +45 -0
- package/dist/core/errors.js +61 -0
- package/dist/core/http.d.ts +29 -0
- package/dist/core/http.js +134 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +10 -0
- package/dist/modules/access/access.schema.d.ts +2307 -0
- package/dist/modules/access/access.schema.js +353 -0
- package/dist/modules/access/access.service.d.ts +55 -0
- package/dist/modules/access/access.service.js +145 -0
- package/dist/modules/access/access.types.d.ts +307 -0
- package/dist/modules/access/access.types.js +3 -0
- package/dist/modules/access/index.d.ts +2 -0
- package/dist/modules/access/index.js +20 -0
- package/dist/modules/card/card.schema.d.ts +27 -0
- package/dist/modules/card/card.schema.js +12 -0
- package/dist/modules/card/card.service.d.ts +10 -0
- package/dist/modules/card/card.service.js +50 -0
- package/dist/modules/card/card.types.d.ts +18 -0
- package/dist/modules/card/card.types.js +2 -0
- package/dist/modules/device/device.schema.d.ts +258 -0
- package/dist/modules/device/device.schema.js +44 -0
- package/dist/modules/device/device.service.d.ts +14 -0
- package/dist/modules/device/device.service.js +69 -0
- package/dist/modules/device/device.types.d.ts +46 -0
- package/dist/modules/device/device.types.js +2 -0
- package/dist/modules/face/face.schema.d.ts +27 -0
- package/dist/modules/face/face.schema.js +12 -0
- package/dist/modules/face/face.service.d.ts +9 -0
- package/dist/modules/face/face.service.js +42 -0
- package/dist/modules/face/face.types.d.ts +17 -0
- package/dist/modules/face/face.types.js +2 -0
- package/dist/modules/person/person.schema.d.ts +270 -0
- package/dist/modules/person/person.schema.js +42 -0
- package/dist/modules/person/person.service.d.ts +16 -0
- package/dist/modules/person/person.service.js +88 -0
- package/dist/modules/person/person.types.d.ts +65 -0
- package/dist/modules/person/person.types.js +2 -0
- package/dist/sdk.d.ts +60 -0
- package/dist/sdk.js +106 -0
- package/package.json +29 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const TraceIdResponseSchema: z.ZodObject<{
|
|
3
|
+
code: z.ZodNumber;
|
|
4
|
+
msg: z.ZodString;
|
|
5
|
+
data: z.ZodObject<{
|
|
6
|
+
traceId: z.ZodString;
|
|
7
|
+
}, "strip", z.ZodTypeAny, {
|
|
8
|
+
traceId: string;
|
|
9
|
+
}, {
|
|
10
|
+
traceId: string;
|
|
11
|
+
}>;
|
|
12
|
+
detail: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
code: number;
|
|
15
|
+
msg: string;
|
|
16
|
+
data: {
|
|
17
|
+
traceId: string;
|
|
18
|
+
};
|
|
19
|
+
detail?: string | null | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
code: number;
|
|
22
|
+
msg: string;
|
|
23
|
+
data: {
|
|
24
|
+
traceId: string;
|
|
25
|
+
};
|
|
26
|
+
detail?: string | null | undefined;
|
|
27
|
+
}>;
|
|
28
|
+
export declare const PersonValidSchema: z.ZodObject<{
|
|
29
|
+
enable: z.ZodBoolean;
|
|
30
|
+
beginTime: z.ZodString;
|
|
31
|
+
endTime: z.ZodString;
|
|
32
|
+
timeType: z.ZodOptional<z.ZodString>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
enable: boolean;
|
|
35
|
+
beginTime: string;
|
|
36
|
+
endTime: string;
|
|
37
|
+
timeType?: string | undefined;
|
|
38
|
+
}, {
|
|
39
|
+
enable: boolean;
|
|
40
|
+
beginTime: string;
|
|
41
|
+
endTime: string;
|
|
42
|
+
timeType?: string | undefined;
|
|
43
|
+
}>;
|
|
44
|
+
export declare const PersonRightPlanSchema: z.ZodObject<{
|
|
45
|
+
doorNo: z.ZodNumber;
|
|
46
|
+
planTemplateNo: z.ZodString;
|
|
47
|
+
}, "strip", z.ZodTypeAny, {
|
|
48
|
+
doorNo: number;
|
|
49
|
+
planTemplateNo: string;
|
|
50
|
+
}, {
|
|
51
|
+
doorNo: number;
|
|
52
|
+
planTemplateNo: string;
|
|
53
|
+
}>;
|
|
54
|
+
export declare const PersonInfoSchema: z.ZodObject<{
|
|
55
|
+
employeeNo: z.ZodString;
|
|
56
|
+
name: z.ZodString;
|
|
57
|
+
userType: z.ZodString;
|
|
58
|
+
Valid: z.ZodOptional<z.ZodObject<{
|
|
59
|
+
enable: z.ZodBoolean;
|
|
60
|
+
beginTime: z.ZodString;
|
|
61
|
+
endTime: z.ZodString;
|
|
62
|
+
timeType: z.ZodOptional<z.ZodString>;
|
|
63
|
+
}, "strip", z.ZodTypeAny, {
|
|
64
|
+
enable: boolean;
|
|
65
|
+
beginTime: string;
|
|
66
|
+
endTime: string;
|
|
67
|
+
timeType?: string | undefined;
|
|
68
|
+
}, {
|
|
69
|
+
enable: boolean;
|
|
70
|
+
beginTime: string;
|
|
71
|
+
endTime: string;
|
|
72
|
+
timeType?: string | undefined;
|
|
73
|
+
}>>;
|
|
74
|
+
password: z.ZodOptional<z.ZodString>;
|
|
75
|
+
doorRight: z.ZodOptional<z.ZodString>;
|
|
76
|
+
RightPlan: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
77
|
+
doorNo: z.ZodNumber;
|
|
78
|
+
planTemplateNo: z.ZodString;
|
|
79
|
+
}, "strip", z.ZodTypeAny, {
|
|
80
|
+
doorNo: number;
|
|
81
|
+
planTemplateNo: string;
|
|
82
|
+
}, {
|
|
83
|
+
doorNo: number;
|
|
84
|
+
planTemplateNo: string;
|
|
85
|
+
}>, "many">>;
|
|
86
|
+
maxOpenDoorTime: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
openDoorTime: z.ZodOptional<z.ZodNumber>;
|
|
88
|
+
numOfCard: z.ZodOptional<z.ZodNumber>;
|
|
89
|
+
numOfFP: z.ZodOptional<z.ZodNumber>;
|
|
90
|
+
numOfFace: z.ZodOptional<z.ZodNumber>;
|
|
91
|
+
}, "strip", z.ZodTypeAny, {
|
|
92
|
+
name: string;
|
|
93
|
+
employeeNo: string;
|
|
94
|
+
userType: string;
|
|
95
|
+
Valid?: {
|
|
96
|
+
enable: boolean;
|
|
97
|
+
beginTime: string;
|
|
98
|
+
endTime: string;
|
|
99
|
+
timeType?: string | undefined;
|
|
100
|
+
} | undefined;
|
|
101
|
+
password?: string | undefined;
|
|
102
|
+
doorRight?: string | undefined;
|
|
103
|
+
RightPlan?: {
|
|
104
|
+
doorNo: number;
|
|
105
|
+
planTemplateNo: string;
|
|
106
|
+
}[] | undefined;
|
|
107
|
+
maxOpenDoorTime?: number | undefined;
|
|
108
|
+
openDoorTime?: number | undefined;
|
|
109
|
+
numOfCard?: number | undefined;
|
|
110
|
+
numOfFP?: number | undefined;
|
|
111
|
+
numOfFace?: number | undefined;
|
|
112
|
+
}, {
|
|
113
|
+
name: string;
|
|
114
|
+
employeeNo: string;
|
|
115
|
+
userType: string;
|
|
116
|
+
Valid?: {
|
|
117
|
+
enable: boolean;
|
|
118
|
+
beginTime: string;
|
|
119
|
+
endTime: string;
|
|
120
|
+
timeType?: string | undefined;
|
|
121
|
+
} | undefined;
|
|
122
|
+
password?: string | undefined;
|
|
123
|
+
doorRight?: string | undefined;
|
|
124
|
+
RightPlan?: {
|
|
125
|
+
doorNo: number;
|
|
126
|
+
planTemplateNo: string;
|
|
127
|
+
}[] | undefined;
|
|
128
|
+
maxOpenDoorTime?: number | undefined;
|
|
129
|
+
openDoorTime?: number | undefined;
|
|
130
|
+
numOfCard?: number | undefined;
|
|
131
|
+
numOfFP?: number | undefined;
|
|
132
|
+
numOfFace?: number | undefined;
|
|
133
|
+
}>;
|
|
134
|
+
export declare const SearchPersonResponseSchema: z.ZodObject<{
|
|
135
|
+
code: z.ZodNumber;
|
|
136
|
+
msg: z.ZodString;
|
|
137
|
+
data: z.ZodArray<z.ZodObject<{
|
|
138
|
+
employeeNo: z.ZodString;
|
|
139
|
+
name: z.ZodString;
|
|
140
|
+
userType: z.ZodString;
|
|
141
|
+
Valid: z.ZodOptional<z.ZodObject<{
|
|
142
|
+
enable: z.ZodBoolean;
|
|
143
|
+
beginTime: z.ZodString;
|
|
144
|
+
endTime: z.ZodString;
|
|
145
|
+
timeType: z.ZodOptional<z.ZodString>;
|
|
146
|
+
}, "strip", z.ZodTypeAny, {
|
|
147
|
+
enable: boolean;
|
|
148
|
+
beginTime: string;
|
|
149
|
+
endTime: string;
|
|
150
|
+
timeType?: string | undefined;
|
|
151
|
+
}, {
|
|
152
|
+
enable: boolean;
|
|
153
|
+
beginTime: string;
|
|
154
|
+
endTime: string;
|
|
155
|
+
timeType?: string | undefined;
|
|
156
|
+
}>>;
|
|
157
|
+
password: z.ZodOptional<z.ZodString>;
|
|
158
|
+
doorRight: z.ZodOptional<z.ZodString>;
|
|
159
|
+
RightPlan: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
160
|
+
doorNo: z.ZodNumber;
|
|
161
|
+
planTemplateNo: z.ZodString;
|
|
162
|
+
}, "strip", z.ZodTypeAny, {
|
|
163
|
+
doorNo: number;
|
|
164
|
+
planTemplateNo: string;
|
|
165
|
+
}, {
|
|
166
|
+
doorNo: number;
|
|
167
|
+
planTemplateNo: string;
|
|
168
|
+
}>, "many">>;
|
|
169
|
+
maxOpenDoorTime: z.ZodOptional<z.ZodNumber>;
|
|
170
|
+
openDoorTime: z.ZodOptional<z.ZodNumber>;
|
|
171
|
+
numOfCard: z.ZodOptional<z.ZodNumber>;
|
|
172
|
+
numOfFP: z.ZodOptional<z.ZodNumber>;
|
|
173
|
+
numOfFace: z.ZodOptional<z.ZodNumber>;
|
|
174
|
+
}, "strip", z.ZodTypeAny, {
|
|
175
|
+
name: string;
|
|
176
|
+
employeeNo: string;
|
|
177
|
+
userType: string;
|
|
178
|
+
Valid?: {
|
|
179
|
+
enable: boolean;
|
|
180
|
+
beginTime: string;
|
|
181
|
+
endTime: string;
|
|
182
|
+
timeType?: string | undefined;
|
|
183
|
+
} | undefined;
|
|
184
|
+
password?: string | undefined;
|
|
185
|
+
doorRight?: string | undefined;
|
|
186
|
+
RightPlan?: {
|
|
187
|
+
doorNo: number;
|
|
188
|
+
planTemplateNo: string;
|
|
189
|
+
}[] | undefined;
|
|
190
|
+
maxOpenDoorTime?: number | undefined;
|
|
191
|
+
openDoorTime?: number | undefined;
|
|
192
|
+
numOfCard?: number | undefined;
|
|
193
|
+
numOfFP?: number | undefined;
|
|
194
|
+
numOfFace?: number | undefined;
|
|
195
|
+
}, {
|
|
196
|
+
name: string;
|
|
197
|
+
employeeNo: string;
|
|
198
|
+
userType: string;
|
|
199
|
+
Valid?: {
|
|
200
|
+
enable: boolean;
|
|
201
|
+
beginTime: string;
|
|
202
|
+
endTime: string;
|
|
203
|
+
timeType?: string | undefined;
|
|
204
|
+
} | undefined;
|
|
205
|
+
password?: string | undefined;
|
|
206
|
+
doorRight?: string | undefined;
|
|
207
|
+
RightPlan?: {
|
|
208
|
+
doorNo: number;
|
|
209
|
+
planTemplateNo: string;
|
|
210
|
+
}[] | undefined;
|
|
211
|
+
maxOpenDoorTime?: number | undefined;
|
|
212
|
+
openDoorTime?: number | undefined;
|
|
213
|
+
numOfCard?: number | undefined;
|
|
214
|
+
numOfFP?: number | undefined;
|
|
215
|
+
numOfFace?: number | undefined;
|
|
216
|
+
}>, "many">;
|
|
217
|
+
count: z.ZodNumber;
|
|
218
|
+
}, "strip", z.ZodTypeAny, {
|
|
219
|
+
code: number;
|
|
220
|
+
msg: string;
|
|
221
|
+
data: {
|
|
222
|
+
name: string;
|
|
223
|
+
employeeNo: string;
|
|
224
|
+
userType: string;
|
|
225
|
+
Valid?: {
|
|
226
|
+
enable: boolean;
|
|
227
|
+
beginTime: string;
|
|
228
|
+
endTime: string;
|
|
229
|
+
timeType?: string | undefined;
|
|
230
|
+
} | undefined;
|
|
231
|
+
password?: string | undefined;
|
|
232
|
+
doorRight?: string | undefined;
|
|
233
|
+
RightPlan?: {
|
|
234
|
+
doorNo: number;
|
|
235
|
+
planTemplateNo: string;
|
|
236
|
+
}[] | undefined;
|
|
237
|
+
maxOpenDoorTime?: number | undefined;
|
|
238
|
+
openDoorTime?: number | undefined;
|
|
239
|
+
numOfCard?: number | undefined;
|
|
240
|
+
numOfFP?: number | undefined;
|
|
241
|
+
numOfFace?: number | undefined;
|
|
242
|
+
}[];
|
|
243
|
+
count: number;
|
|
244
|
+
}, {
|
|
245
|
+
code: number;
|
|
246
|
+
msg: string;
|
|
247
|
+
data: {
|
|
248
|
+
name: string;
|
|
249
|
+
employeeNo: string;
|
|
250
|
+
userType: string;
|
|
251
|
+
Valid?: {
|
|
252
|
+
enable: boolean;
|
|
253
|
+
beginTime: string;
|
|
254
|
+
endTime: string;
|
|
255
|
+
timeType?: string | undefined;
|
|
256
|
+
} | undefined;
|
|
257
|
+
password?: string | undefined;
|
|
258
|
+
doorRight?: string | undefined;
|
|
259
|
+
RightPlan?: {
|
|
260
|
+
doorNo: number;
|
|
261
|
+
planTemplateNo: string;
|
|
262
|
+
}[] | undefined;
|
|
263
|
+
maxOpenDoorTime?: number | undefined;
|
|
264
|
+
openDoorTime?: number | undefined;
|
|
265
|
+
numOfCard?: number | undefined;
|
|
266
|
+
numOfFP?: number | undefined;
|
|
267
|
+
numOfFace?: number | undefined;
|
|
268
|
+
}[];
|
|
269
|
+
count: number;
|
|
270
|
+
}>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SearchPersonResponseSchema = exports.PersonInfoSchema = exports.PersonRightPlanSchema = exports.PersonValidSchema = exports.TraceIdResponseSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
exports.TraceIdResponseSchema = zod_1.z.object({
|
|
6
|
+
code: zod_1.z.number(),
|
|
7
|
+
msg: zod_1.z.string(),
|
|
8
|
+
data: zod_1.z.object({
|
|
9
|
+
traceId: zod_1.z.string(),
|
|
10
|
+
}),
|
|
11
|
+
detail: zod_1.z.string().nullable().optional(),
|
|
12
|
+
});
|
|
13
|
+
exports.PersonValidSchema = zod_1.z.object({
|
|
14
|
+
enable: zod_1.z.boolean(),
|
|
15
|
+
beginTime: zod_1.z.string(),
|
|
16
|
+
endTime: zod_1.z.string(),
|
|
17
|
+
timeType: zod_1.z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
exports.PersonRightPlanSchema = zod_1.z.object({
|
|
20
|
+
doorNo: zod_1.z.number(),
|
|
21
|
+
planTemplateNo: zod_1.z.string(),
|
|
22
|
+
});
|
|
23
|
+
exports.PersonInfoSchema = zod_1.z.object({
|
|
24
|
+
employeeNo: zod_1.z.string(),
|
|
25
|
+
name: zod_1.z.string(),
|
|
26
|
+
userType: zod_1.z.string(),
|
|
27
|
+
Valid: exports.PersonValidSchema.optional(),
|
|
28
|
+
password: zod_1.z.string().optional(),
|
|
29
|
+
doorRight: zod_1.z.string().optional(),
|
|
30
|
+
RightPlan: zod_1.z.array(exports.PersonRightPlanSchema).optional(),
|
|
31
|
+
maxOpenDoorTime: zod_1.z.number().optional(),
|
|
32
|
+
openDoorTime: zod_1.z.number().optional(),
|
|
33
|
+
numOfCard: zod_1.z.number().optional(),
|
|
34
|
+
numOfFP: zod_1.z.number().optional(),
|
|
35
|
+
numOfFace: zod_1.z.number().optional(),
|
|
36
|
+
});
|
|
37
|
+
exports.SearchPersonResponseSchema = zod_1.z.object({
|
|
38
|
+
code: zod_1.z.number(),
|
|
39
|
+
msg: zod_1.z.string(),
|
|
40
|
+
data: zod_1.z.array(exports.PersonInfoSchema),
|
|
41
|
+
count: zod_1.z.number(),
|
|
42
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { HttpClient } from '../../core/http';
|
|
2
|
+
import type { CreatePersonInput, DeletePersonInput, BatchDeletePersonInput, SearchPersonInput, TraceIdResponse, PersonInfo } from './person.types';
|
|
3
|
+
export declare class PersonService {
|
|
4
|
+
private readonly http;
|
|
5
|
+
constructor(http: HttpClient);
|
|
6
|
+
create(input: CreatePersonInput): Promise<TraceIdResponse>;
|
|
7
|
+
update(input: CreatePersonInput): Promise<TraceIdResponse>;
|
|
8
|
+
delete(input: DeletePersonInput): Promise<TraceIdResponse>;
|
|
9
|
+
batchDelete(input: BatchDeletePersonInput): Promise<TraceIdResponse>;
|
|
10
|
+
search(input: SearchPersonInput): Promise<{
|
|
11
|
+
data: PersonInfo[];
|
|
12
|
+
count: number;
|
|
13
|
+
}>;
|
|
14
|
+
get(deviceSerial: string, employeeNo: string): Promise<PersonInfo | null>;
|
|
15
|
+
private formatDateTime;
|
|
16
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PersonService = void 0;
|
|
4
|
+
const person_schema_1 = require("./person.schema");
|
|
5
|
+
class PersonService {
|
|
6
|
+
constructor(http) {
|
|
7
|
+
this.http = http;
|
|
8
|
+
}
|
|
9
|
+
async create(input) {
|
|
10
|
+
const { deviceSerial, employeeNo, name, userType = 'normal', permanentValid = false, enableBeginTime = this.formatDateTime(new Date()), enableEndTime = '2037-12-31T23:59:59', doorRight = [1], doorRightPlan = [{ doorNo: 1, planTemplateId: [1] }], password, maxOpenDoorTime, } = input;
|
|
11
|
+
const userInfo = {
|
|
12
|
+
employeeNo,
|
|
13
|
+
name,
|
|
14
|
+
userType,
|
|
15
|
+
permanentValid,
|
|
16
|
+
enableBeginTime,
|
|
17
|
+
enableEndTime,
|
|
18
|
+
doorRight,
|
|
19
|
+
doorRightPlan,
|
|
20
|
+
};
|
|
21
|
+
if (password !== undefined) {
|
|
22
|
+
userInfo.password = password;
|
|
23
|
+
}
|
|
24
|
+
if (maxOpenDoorTime !== undefined) {
|
|
25
|
+
userInfo.maxOpenDoorTime = maxOpenDoorTime;
|
|
26
|
+
}
|
|
27
|
+
const response = await this.http.post('/device/direct/v1/userInfo/addOneRecord', {
|
|
28
|
+
deviceSerial,
|
|
29
|
+
payload: { userInfo },
|
|
30
|
+
}, person_schema_1.TraceIdResponseSchema);
|
|
31
|
+
return response.data;
|
|
32
|
+
}
|
|
33
|
+
async update(input) {
|
|
34
|
+
return this.create(input);
|
|
35
|
+
}
|
|
36
|
+
async delete(input) {
|
|
37
|
+
const { deviceSerial, employeeNo } = input;
|
|
38
|
+
const response = await this.http.post('/device/direct/v1/userInfo/deleteByKey', {
|
|
39
|
+
deviceSerial,
|
|
40
|
+
payload: {
|
|
41
|
+
userInfo: { employeeNo },
|
|
42
|
+
},
|
|
43
|
+
}, person_schema_1.TraceIdResponseSchema);
|
|
44
|
+
return response.data;
|
|
45
|
+
}
|
|
46
|
+
async batchDelete(input) {
|
|
47
|
+
const { deviceSerial, employeeNos } = input;
|
|
48
|
+
if (employeeNos.length === 0) {
|
|
49
|
+
throw new Error('employeeNos cannot be empty');
|
|
50
|
+
}
|
|
51
|
+
const response = await this.http.post('/device/direct/v1/userInfo/batchDeleteByKey', {
|
|
52
|
+
deviceSerial,
|
|
53
|
+
payload: {
|
|
54
|
+
userInfo: employeeNos.map((employeeNo) => ({ employeeNo })),
|
|
55
|
+
},
|
|
56
|
+
}, person_schema_1.TraceIdResponseSchema);
|
|
57
|
+
return response.data;
|
|
58
|
+
}
|
|
59
|
+
async search(input) {
|
|
60
|
+
const { deviceSerial, page = 1, size = 20, keyword } = input;
|
|
61
|
+
const requestData = {
|
|
62
|
+
deviceSerial,
|
|
63
|
+
page,
|
|
64
|
+
size,
|
|
65
|
+
};
|
|
66
|
+
if (keyword) {
|
|
67
|
+
requestData.keyword = keyword;
|
|
68
|
+
}
|
|
69
|
+
const response = await this.http.post('/device/direct/v1/userInfo/search', requestData, person_schema_1.SearchPersonResponseSchema);
|
|
70
|
+
return {
|
|
71
|
+
data: response.data,
|
|
72
|
+
count: response.count,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
async get(deviceSerial, employeeNo) {
|
|
76
|
+
const result = await this.search({
|
|
77
|
+
deviceSerial,
|
|
78
|
+
keyword: employeeNo,
|
|
79
|
+
size: 1,
|
|
80
|
+
});
|
|
81
|
+
return result.data.find((p) => p.employeeNo === employeeNo) ?? null;
|
|
82
|
+
}
|
|
83
|
+
formatDateTime(date) {
|
|
84
|
+
const pad = (n) => n.toString().padStart(2, '0');
|
|
85
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.PersonService = PersonService;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export type UserType = 'normal' | 'visitor' | 'blackList';
|
|
2
|
+
export interface DoorRightPlan {
|
|
3
|
+
doorNo: number;
|
|
4
|
+
planTemplateId: number[];
|
|
5
|
+
}
|
|
6
|
+
export interface CreatePersonInput {
|
|
7
|
+
deviceSerial: string;
|
|
8
|
+
employeeNo: string;
|
|
9
|
+
name: string;
|
|
10
|
+
userType?: UserType;
|
|
11
|
+
permanentValid?: boolean;
|
|
12
|
+
enableBeginTime?: string;
|
|
13
|
+
enableEndTime?: string;
|
|
14
|
+
doorRight?: number[];
|
|
15
|
+
doorRightPlan?: DoorRightPlan[];
|
|
16
|
+
password?: string;
|
|
17
|
+
maxOpenDoorTime?: number;
|
|
18
|
+
}
|
|
19
|
+
export interface DeletePersonInput {
|
|
20
|
+
deviceSerial: string;
|
|
21
|
+
employeeNo: string;
|
|
22
|
+
}
|
|
23
|
+
export interface BatchDeletePersonInput {
|
|
24
|
+
deviceSerial: string;
|
|
25
|
+
employeeNos: string[];
|
|
26
|
+
}
|
|
27
|
+
export interface SearchPersonInput {
|
|
28
|
+
deviceSerial: string;
|
|
29
|
+
page?: number;
|
|
30
|
+
size?: number;
|
|
31
|
+
keyword?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface PersonValid {
|
|
34
|
+
enable: boolean;
|
|
35
|
+
beginTime: string;
|
|
36
|
+
endTime: string;
|
|
37
|
+
timeType?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface PersonRightPlan {
|
|
40
|
+
doorNo: number;
|
|
41
|
+
planTemplateNo: string;
|
|
42
|
+
}
|
|
43
|
+
export interface PersonInfo {
|
|
44
|
+
employeeNo: string;
|
|
45
|
+
name: string;
|
|
46
|
+
userType: string;
|
|
47
|
+
Valid?: PersonValid;
|
|
48
|
+
password?: string;
|
|
49
|
+
doorRight?: string;
|
|
50
|
+
RightPlan?: PersonRightPlan[];
|
|
51
|
+
maxOpenDoorTime?: number;
|
|
52
|
+
openDoorTime?: number;
|
|
53
|
+
numOfCard?: number;
|
|
54
|
+
numOfFP?: number;
|
|
55
|
+
numOfFace?: number;
|
|
56
|
+
}
|
|
57
|
+
export interface TraceIdResponse {
|
|
58
|
+
traceId: string;
|
|
59
|
+
}
|
|
60
|
+
export interface SearchPersonResponse {
|
|
61
|
+
code: number;
|
|
62
|
+
msg: string;
|
|
63
|
+
data: PersonInfo[];
|
|
64
|
+
count: number;
|
|
65
|
+
}
|
package/dist/sdk.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type HikSdkOptions } from './core/config';
|
|
2
|
+
import { PersonService } from './modules/person/person.service';
|
|
3
|
+
import { FaceService } from './modules/face/face.service';
|
|
4
|
+
import { CardService } from './modules/card/card.service';
|
|
5
|
+
import { DeviceService } from './modules/device/device.service';
|
|
6
|
+
import { AccessService } from './modules/access/access.service';
|
|
7
|
+
import type { DoorRightPlan } from './modules/person/person.types';
|
|
8
|
+
export declare class HikSdk {
|
|
9
|
+
readonly person: PersonService;
|
|
10
|
+
readonly face: FaceService;
|
|
11
|
+
readonly card: CardService;
|
|
12
|
+
readonly device: DeviceService;
|
|
13
|
+
readonly access: AccessService;
|
|
14
|
+
private readonly config;
|
|
15
|
+
private readonly authManager;
|
|
16
|
+
private readonly httpClient;
|
|
17
|
+
constructor(options: HikSdkOptions);
|
|
18
|
+
getUserInfo(): {
|
|
19
|
+
teamNo: string;
|
|
20
|
+
personNo: string;
|
|
21
|
+
accountNo: string;
|
|
22
|
+
} | null;
|
|
23
|
+
createPersonWithFace(input: {
|
|
24
|
+
deviceSerial: string;
|
|
25
|
+
employeeNo: string;
|
|
26
|
+
name: string;
|
|
27
|
+
faceURL: string;
|
|
28
|
+
userType?: 'normal' | 'visitor' | 'blackList';
|
|
29
|
+
permanentValid?: boolean;
|
|
30
|
+
enableBeginTime?: string;
|
|
31
|
+
enableEndTime?: string;
|
|
32
|
+
doorRight?: number[];
|
|
33
|
+
doorRightPlan?: DoorRightPlan[];
|
|
34
|
+
}): Promise<{
|
|
35
|
+
personTraceId: string;
|
|
36
|
+
faceTraceId: string;
|
|
37
|
+
}>;
|
|
38
|
+
createPersonWithFaceAndCard(input: {
|
|
39
|
+
deviceSerial: string;
|
|
40
|
+
employeeNo: string;
|
|
41
|
+
name: string;
|
|
42
|
+
faceURL: string;
|
|
43
|
+
cardNo: string;
|
|
44
|
+
userType?: 'normal' | 'visitor' | 'blackList';
|
|
45
|
+
permanentValid?: boolean;
|
|
46
|
+
enableBeginTime?: string;
|
|
47
|
+
enableEndTime?: string;
|
|
48
|
+
doorRight?: number[];
|
|
49
|
+
doorRightPlan?: DoorRightPlan[];
|
|
50
|
+
cardType?: 'normalCard' | 'patrolCard' | 'hijackCard' | 'superCard' | 'dismissingCard' | 'emergencyCard';
|
|
51
|
+
}): Promise<{
|
|
52
|
+
personTraceId: string;
|
|
53
|
+
faceTraceId: string;
|
|
54
|
+
cardTraceId: string;
|
|
55
|
+
}>;
|
|
56
|
+
deletePersonComplete(deviceSerial: string, employeeNo: string): Promise<{
|
|
57
|
+
faceTraceId?: string;
|
|
58
|
+
personTraceId: string;
|
|
59
|
+
}>;
|
|
60
|
+
}
|
package/dist/sdk.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HikSdk = void 0;
|
|
4
|
+
const config_1 = require("./core/config");
|
|
5
|
+
const auth_1 = require("./core/auth");
|
|
6
|
+
const http_1 = require("./core/http");
|
|
7
|
+
const person_service_1 = require("./modules/person/person.service");
|
|
8
|
+
const face_service_1 = require("./modules/face/face.service");
|
|
9
|
+
const card_service_1 = require("./modules/card/card.service");
|
|
10
|
+
const device_service_1 = require("./modules/device/device.service");
|
|
11
|
+
const access_service_1 = require("./modules/access/access.service");
|
|
12
|
+
const DEFAULT_REDIRECT_URL = 'https://iot.alan.fit/api/hik/callback';
|
|
13
|
+
class HikSdk {
|
|
14
|
+
constructor(options) {
|
|
15
|
+
this.config = config_1.HikConfigSchema.parse({
|
|
16
|
+
appKey: options.appKey,
|
|
17
|
+
appSecret: options.appSecret,
|
|
18
|
+
baseUrl: options.baseUrl ?? 'https://open-api.hikiot.com',
|
|
19
|
+
enableEncrypt: options.enableEncrypt ?? true, // 海康互联默认开启加密
|
|
20
|
+
timeout: options.timeout ?? 30000,
|
|
21
|
+
});
|
|
22
|
+
this.authManager = new auth_1.AuthManager(this.config, {
|
|
23
|
+
userName: options.userName,
|
|
24
|
+
password: options.password,
|
|
25
|
+
redirectUrl: options.redirectUrl ?? DEFAULT_REDIRECT_URL,
|
|
26
|
+
});
|
|
27
|
+
this.httpClient = new http_1.HttpClient(this.config, this.authManager);
|
|
28
|
+
this.person = new person_service_1.PersonService(this.httpClient);
|
|
29
|
+
this.face = new face_service_1.FaceService(this.httpClient);
|
|
30
|
+
this.card = new card_service_1.CardService(this.httpClient);
|
|
31
|
+
this.device = new device_service_1.DeviceService(this.httpClient);
|
|
32
|
+
this.access = new access_service_1.AccessService(this.httpClient);
|
|
33
|
+
}
|
|
34
|
+
getUserInfo() {
|
|
35
|
+
return this.authManager.getUserInfo();
|
|
36
|
+
}
|
|
37
|
+
async createPersonWithFace(input) {
|
|
38
|
+
const { deviceSerial, employeeNo, name, faceURL, userType, permanentValid, enableBeginTime, enableEndTime, doorRight, doorRightPlan, } = input;
|
|
39
|
+
const personResult = await this.person.create({
|
|
40
|
+
deviceSerial,
|
|
41
|
+
employeeNo,
|
|
42
|
+
name,
|
|
43
|
+
userType,
|
|
44
|
+
permanentValid,
|
|
45
|
+
enableBeginTime,
|
|
46
|
+
enableEndTime,
|
|
47
|
+
doorRight,
|
|
48
|
+
doorRightPlan,
|
|
49
|
+
});
|
|
50
|
+
const faceResult = await this.face.add({
|
|
51
|
+
deviceSerial,
|
|
52
|
+
employeeNo,
|
|
53
|
+
faceURL,
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
personTraceId: personResult.traceId,
|
|
57
|
+
faceTraceId: faceResult.traceId,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
async createPersonWithFaceAndCard(input) {
|
|
61
|
+
const { deviceSerial, employeeNo, name, faceURL, cardNo, userType, permanentValid, enableBeginTime, enableEndTime, doorRight, doorRightPlan, cardType, } = input;
|
|
62
|
+
const personResult = await this.person.create({
|
|
63
|
+
deviceSerial,
|
|
64
|
+
employeeNo,
|
|
65
|
+
name,
|
|
66
|
+
userType,
|
|
67
|
+
permanentValid,
|
|
68
|
+
enableBeginTime,
|
|
69
|
+
enableEndTime,
|
|
70
|
+
doorRight,
|
|
71
|
+
doorRightPlan,
|
|
72
|
+
});
|
|
73
|
+
const faceResult = await this.face.add({
|
|
74
|
+
deviceSerial,
|
|
75
|
+
employeeNo,
|
|
76
|
+
faceURL,
|
|
77
|
+
});
|
|
78
|
+
const cardResult = await this.card.add({
|
|
79
|
+
deviceSerial,
|
|
80
|
+
employeeNo,
|
|
81
|
+
cardNo,
|
|
82
|
+
cardType,
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
personTraceId: personResult.traceId,
|
|
86
|
+
faceTraceId: faceResult.traceId,
|
|
87
|
+
cardTraceId: cardResult.traceId,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
async deletePersonComplete(deviceSerial, employeeNo) {
|
|
91
|
+
let faceTraceId;
|
|
92
|
+
try {
|
|
93
|
+
const faceResult = await this.face.delete({ deviceSerial, employeeNo });
|
|
94
|
+
faceTraceId = faceResult.traceId;
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Face may not exist, ignore
|
|
98
|
+
}
|
|
99
|
+
const personResult = await this.person.delete({ deviceSerial, employeeNo });
|
|
100
|
+
return {
|
|
101
|
+
faceTraceId,
|
|
102
|
+
personTraceId: personResult.traceId,
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
exports.HikSdk = HikSdk;
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "hik-iot-sdk",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Hikvision IoT Node.js SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"demo": "tsx examples/face-access-demo.ts",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"engines": {
|
|
16
|
+
"node": ">=14.0.0"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"axios": "^0.27.0",
|
|
20
|
+
"node-forge": "^1.3.0",
|
|
21
|
+
"pino": "^8.0.0",
|
|
22
|
+
"zod": "^3.20.0"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^14.18.0",
|
|
26
|
+
"@types/node-forge": "^1.3.14",
|
|
27
|
+
"typescript": "^5.0.0"
|
|
28
|
+
}
|
|
29
|
+
}
|