@larksuiteoapi/node-sdk
Version:
larksuite open sdk for nodejs
1,006 lines (977 loc) • 4.51 MB
JavaScript
/**
* MIT License
*
* Copyright (c) 2022 Lark Technologies Pte. Ltd.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice, shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var get = require('lodash.get');
var axios = require('axios');
var crypto = require('crypto');
var qs = require('qs');
var identity = require('lodash.identity');
var pickBy = require('lodash.pickby');
var fs = require('fs');
var merge = require('lodash.merge');
var qs$1 = require('querystring');
var WebSocket = require('ws');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
var crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
var identity__default = /*#__PURE__*/_interopDefaultLegacy(identity);
var pickBy__default = /*#__PURE__*/_interopDefaultLegacy(pickBy);
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
var merge__default = /*#__PURE__*/_interopDefaultLegacy(merge);
var qs__default = /*#__PURE__*/_interopDefaultLegacy(qs$1);
var WebSocket__default = /*#__PURE__*/_interopDefaultLegacy(WebSocket);
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
const defaultHttpInstance = axios__default["default"].create();
defaultHttpInstance.interceptors.request.use((req) => {
if (req.headers) {
req.headers['User-Agent'] = 'oapi-node-sdk/1.0.0';
}
return req;
}, undefined, { synchronous: true });
defaultHttpInstance.interceptors.response.use((resp) => resp.data);
exports.AppType = void 0;
(function (AppType) {
AppType[AppType["SelfBuild"] = 0] = "SelfBuild";
AppType[AppType["ISV"] = 1] = "ISV";
})(exports.AppType || (exports.AppType = {}));
exports.Domain = void 0;
(function (Domain) {
Domain[Domain["Feishu"] = 0] = "Feishu";
Domain[Domain["Lark"] = 1] = "Lark";
})(exports.Domain || (exports.Domain = {}));
exports.LoggerLevel = void 0;
(function (LoggerLevel) {
LoggerLevel[LoggerLevel["fatal"] = 0] = "fatal";
LoggerLevel[LoggerLevel["error"] = 1] = "error";
LoggerLevel[LoggerLevel["warn"] = 2] = "warn";
LoggerLevel[LoggerLevel["info"] = 3] = "info";
LoggerLevel[LoggerLevel["debug"] = 4] = "debug";
LoggerLevel[LoggerLevel["trace"] = 5] = "trace";
})(exports.LoggerLevel || (exports.LoggerLevel = {}));
const CEventType = Symbol('event-type');
const CTenantKey = Symbol('tenant-key');
const CAppTicket = Symbol('app-ticket');
const CTenantAccessToken = Symbol('tenant-access-token');
const CWithHelpdeskAuthorization = Symbol('with-helpdesk-authorization');
const CWithUserAccessToken = Symbol('with-user-access-token');
const CUserAccessToken = Symbol('user-access-token');
const CAilySessionRecord = Symbol('aily-session-record');
const string2Base64 = (content) => Buffer.from(content).toString('base64');
class DefaultCache {
constructor() {
this.values = new Map();
}
// When there is a namespace, splice the namespace and key to form a new key
getCacheKey(key, namespace) {
if (namespace) {
return `${namespace}/${key.toString()}`;
}
return key;
}
get(key, options) {
return __awaiter(this, void 0, void 0, function* () {
const cacheKey = this.getCacheKey(key, get__default["default"](options, 'namespace'));
const data = this.values.get(cacheKey);
if (data) {
const { value, expiredTime } = data;
if (!expiredTime || expiredTime - new Date().getTime() > 0) {
return value;
}
}
return undefined;
});
}
set(key, value, expiredTime, options) {
return __awaiter(this, void 0, void 0, function* () {
const cacheKey = this.getCacheKey(key, get__default["default"](options, 'namespace'));
this.values.set(cacheKey, {
value,
expiredTime,
});
return true;
});
}
}
const internalCache = new DefaultCache();
class AESCipher {
constructor(key) {
const hash = crypto__default["default"].createHash('sha256');
hash.update(key);
this.key = hash.digest();
}
decrypt(encrypt) {
const encryptBuffer = Buffer.from(encrypt, 'base64');
const decipher = crypto__default["default"].createDecipheriv('aes-256-cbc', this.key, encryptBuffer.slice(0, 16));
let decrypted = decipher.update(encryptBuffer.slice(16).toString('hex'), 'hex', 'utf8');
decrypted += decipher.final('utf8');
return decrypted;
}
}
const formatDomain = (domain) => {
switch (domain) {
case exports.Domain.Feishu:
return 'https://open.feishu.cn';
case exports.Domain.Lark:
return 'https://open.larksuite.com';
default:
return domain;
}
};
const fillApiPath = (apiPath, pathSupplement = {}) => apiPath.replace(/:([^/]+)/g, (_, $1) => {
if (pathSupplement[$1] !== undefined) {
return pathSupplement[$1];
}
throw new Error(`request miss ${$1} path argument`);
});
const assert = (predication, callback) => __awaiter(void 0, void 0, void 0, function* () {
const isInvoke = typeof predication === 'function' ? predication() : predication;
if (isInvoke) {
yield callback();
}
});
const formatUrl = (url) => (url ? url.replace(/^\//, '') : '');
const pick = (obj, keys = []) => {
const result = {};
if (!obj) {
return result;
}
keys.forEach(key => {
if (Object.prototype.hasOwnProperty.call(obj, key)) {
result[key] = obj[key];
}
});
return result;
};
const formatErrors = (e) => {
if (e instanceof axios.AxiosError) {
const { message, response, request, config } = pick(e, [
'message',
'response',
'request',
'config',
]);
const filteredErrorInfo = {
message,
config: pick(config, ['data', 'url', 'params', 'method']),
request: pick(request, ['protocol', 'host', 'path', 'method']),
response: pick(response, ['data', 'status', 'statusText']),
};
const errors = [filteredErrorInfo];
const specificError = get__default["default"](e, 'response.data');
if (specificError) {
errors.push(Object.assign(Object.assign({}, specificError), (specificError.error ? specificError.error : {})));
}
return errors;
}
return [e];
};
// auto gen
class Client$14 {
constructor() {
/**
* 智能门禁
*/
this.acs = {
/**
* access_record.access_photo
*/
accessRecordAccessPhoto: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=access_record.access_photo&apiName=get&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/access_record-access_photo/get document }
*
* 下载开门时的人脸识别图片
*
* 用户在门禁考勤机上成功开门或打卡后,智能门禁应用都会生成一条门禁记录,对于使用人脸识别方式进行开门的识别记录,还会有抓拍图。;;可以用该接口下载开门时的人脸识别照片。
*/
get: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/access_records/:access_record_id/access_photo`, path),
method: "GET",
headers,
data,
params,
responseType: "stream",
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
const checkIsReadable = () => {
const consumedError = "The stream has already been consumed";
if (!res.readable) {
this.logger.error(consumedError);
throw new Error(consumedError);
}
};
return {
writeFile: (filePath) => __awaiter(this, void 0, void 0, function* () {
checkIsReadable();
return new Promise((resolve, reject) => {
const writableStream = fs__default["default"].createWriteStream(filePath);
writableStream.on("finish", () => {
resolve(filePath);
});
writableStream.on("error", (e) => {
reject(e);
});
res.pipe(writableStream);
});
}),
getReadableStream: () => {
checkIsReadable();
return res;
},
};
}),
},
/**
* 门禁记录
*/
accessRecord: {
listWithIterator: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const sendRequest = (innerPayload) => __awaiter(this, void 0, void 0, function* () {
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/access_records`, path),
method: "GET",
headers: pickBy__default["default"](innerPayload.headers, identity__default["default"]),
params: pickBy__default["default"](innerPayload.params, identity__default["default"]),
data,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
});
return res;
});
const Iterable = {
[Symbol.asyncIterator]() {
return __asyncGenerator(this, arguments, function* _a() {
let hasMore = true;
let pageToken;
while (hasMore) {
try {
const res = yield __await(sendRequest({
headers,
params: Object.assign(Object.assign({}, params), { page_token: pageToken }),
data,
}));
const _b = get__default["default"](res, "data") || {}, {
// @ts-ignore
has_more,
// @ts-ignore
page_token,
// @ts-ignore
next_page_token } = _b, rest = __rest(_b, ["has_more", "page_token", "next_page_token"]);
yield yield __await(rest);
hasMore = Boolean(has_more);
pageToken = page_token || next_page_token;
}
catch (e) {
yield yield __await(null);
break;
}
}
});
},
};
return Iterable;
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=access_record&apiName=list&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/access_record/list document }
*
* 获取门禁记录列表
*
* 用户在门禁考勤机上成功开门或打卡后,智能门禁应用都会生成一条门禁记录。;;该接口返回满足查询参数的识别记录。
*/
list: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/access_records`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
/**
* 门禁设备
*/
device: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=device&apiName=list&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/device/list document }
*
* 获取门禁设备列表
*
* 使用该接口获取租户内所有门禁设备。
*/
list: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/devices`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
/**
* rule_external
*/
ruleExternal: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=rule_external&apiName=create&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create&project=acs&resource=rule_external&version=v1 document }
*/
create: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/rule_external`, path),
method: "POST",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=rule_external&apiName=delete&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=delete&project=acs&resource=rule_external&version=v1 document }
*/
delete: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/rule_external`, path),
method: "DELETE",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=rule_external&apiName=device_bind&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=device_bind&project=acs&resource=rule_external&version=v1 document }
*/
deviceBind: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/rule_external/device_bind`, path),
method: "POST",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=rule_external&apiName=get&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=get&project=acs&resource=rule_external&version=v1 document }
*/
get: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/rule_external`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
/**
* user.face
*/
userFace: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=user.face&apiName=get&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/user-face/get document }
*
* 下载人脸图片
*
* 对于已经录入人脸图片的用户,可以使用该接口下载用户人脸图片。
*/
get: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/users/:user_id/face`, path),
method: "GET",
headers,
data,
params,
responseType: "stream",
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
const checkIsReadable = () => {
const consumedError = "The stream has already been consumed";
if (!res.readable) {
this.logger.error(consumedError);
throw new Error(consumedError);
}
};
return {
writeFile: (filePath) => __awaiter(this, void 0, void 0, function* () {
checkIsReadable();
return new Promise((resolve, reject) => {
const writableStream = fs__default["default"].createWriteStream(filePath);
writableStream.on("finish", () => {
resolve(filePath);
});
writableStream.on("error", (e) => {
reject(e);
});
res.pipe(writableStream);
});
}),
getReadableStream: () => {
checkIsReadable();
return res;
},
};
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=user.face&apiName=update&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/user-face/update document }
*
* 上传人脸图片
*
* 用户需要录入人脸图片才可以使用门禁考勤机。使用该 API 上传门禁用户的人脸图片。
*/
update: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/users/:user_id/face`, path),
method: "PUT",
data,
params,
headers: Object.assign(Object.assign({}, headers), { "Content-Type": "multipart/form-data" }),
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
return get__default["default"](res, "data", null);
}),
},
/**
* 用户管理
*/
user: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=user&apiName=get&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/user/get document }
*
* 获取单个用户信息
*
* 该接口用于获取智能门禁中单个用户的信息。
*
* 只能获取已加入智能门禁权限组的用户
*/
get: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/users/:user_id`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
listWithIterator: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const sendRequest = (innerPayload) => __awaiter(this, void 0, void 0, function* () {
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/users`, path),
method: "GET",
headers: pickBy__default["default"](innerPayload.headers, identity__default["default"]),
params: pickBy__default["default"](innerPayload.params, identity__default["default"]),
data,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
});
return res;
});
const Iterable = {
[Symbol.asyncIterator]() {
return __asyncGenerator(this, arguments, function* _a() {
let hasMore = true;
let pageToken;
while (hasMore) {
try {
const res = yield __await(sendRequest({
headers,
params: Object.assign(Object.assign({}, params), { page_token: pageToken }),
data,
}));
const _b = get__default["default"](res, "data") || {}, {
// @ts-ignore
has_more,
// @ts-ignore
page_token,
// @ts-ignore
next_page_token } = _b, rest = __rest(_b, ["has_more", "page_token", "next_page_token"]);
yield yield __await(rest);
hasMore = Boolean(has_more);
pageToken = page_token || next_page_token;
}
catch (e) {
yield yield __await(null);
break;
}
}
});
},
};
return Iterable;
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=user&apiName=list&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/user/list document }
*
* 获取用户列表
*
* 使用该接口获取智能门禁中所有用户信息。
*
* 只能获取已加入智能门禁权限组的用户。
*/
list: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/users`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=user&apiName=patch&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/user/patch document }
*
* 修改用户部分信息
*
* 飞书智能门禁在人脸识别成功后会有韦根信号输出,输出用户的卡号。;对于使用韦根协议的门禁系统,企业可使用该接口录入用户卡号。
*/
patch: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/users/:user_id`, path),
method: "PATCH",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
/**
* visitor
*/
visitor: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=visitor&apiName=create&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create&project=acs&resource=visitor&version=v1 document }
*/
create: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/visitors`, path),
method: "POST",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=visitor&apiName=delete&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=delete&project=acs&resource=visitor&version=v1 document }
*/
delete: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/visitors/:visitor_id`, path),
method: "DELETE",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
v1: {
/**
* access_record.access_photo
*/
accessRecordAccessPhoto: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=access_record.access_photo&apiName=get&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/access_record-access_photo/get document }
*
* 下载开门时的人脸识别图片
*
* 用户在门禁考勤机上成功开门或打卡后,智能门禁应用都会生成一条门禁记录,对于使用人脸识别方式进行开门的识别记录,还会有抓拍图。;;可以用该接口下载开门时的人脸识别照片。
*/
get: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/access_records/:access_record_id/access_photo`, path),
method: "GET",
headers,
data,
params,
responseType: "stream",
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
const checkIsReadable = () => {
const consumedError = "The stream has already been consumed";
if (!res.readable) {
this.logger.error(consumedError);
throw new Error(consumedError);
}
};
return {
writeFile: (filePath) => __awaiter(this, void 0, void 0, function* () {
checkIsReadable();
return new Promise((resolve, reject) => {
const writableStream = fs__default["default"].createWriteStream(filePath);
writableStream.on("finish", () => {
resolve(filePath);
});
writableStream.on("error", (e) => {
reject(e);
});
res.pipe(writableStream);
});
}),
getReadableStream: () => {
checkIsReadable();
return res;
},
};
}),
},
/**
* 门禁记录
*/
accessRecord: {
listWithIterator: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
const sendRequest = (innerPayload) => __awaiter(this, void 0, void 0, function* () {
const res = yield this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/access_records`, path),
method: "GET",
headers: pickBy__default["default"](innerPayload.headers, identity__default["default"]),
params: pickBy__default["default"](innerPayload.params, identity__default["default"]),
data,
paramsSerializer: (params) => qs.stringify(params, {
arrayFormat: "repeat",
}),
})
.catch((e) => {
this.logger.error(formatErrors(e));
});
return res;
});
const Iterable = {
[Symbol.asyncIterator]() {
return __asyncGenerator(this, arguments, function* _a() {
let hasMore = true;
let pageToken;
while (hasMore) {
try {
const res = yield __await(sendRequest({
headers,
params: Object.assign(Object.assign({}, params), { page_token: pageToken }),
data,
}));
const _b = get__default["default"](res, "data") || {}, {
// @ts-ignore
has_more,
// @ts-ignore
page_token,
// @ts-ignore
next_page_token } = _b, rest = __rest(_b, ["has_more", "page_token", "next_page_token"]);
yield yield __await(rest);
hasMore = Boolean(has_more);
pageToken = page_token || next_page_token;
}
catch (e) {
yield yield __await(null);
break;
}
}
});
},
};
return Iterable;
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=access_record&apiName=list&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/access_record/list document }
*
* 获取门禁记录列表
*
* 用户在门禁考勤机上成功开门或打卡后,智能门禁应用都会生成一条门禁记录。;;该接口返回满足查询参数的识别记录。
*/
list: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/access_records`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
/**
* 门禁设备
*/
device: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=device&apiName=list&version=v1 click to debug }
*
* {@link https://open.feishu.cn/document/uAjLw4CM/ukTMukTMukTM/acs-v1/device/list document }
*
* 获取门禁设备列表
*
* 使用该接口获取租户内所有门禁设备。
*/
list: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/devices`, path),
method: "GET",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
},
/**
* rule_external
*/
ruleExternal: {
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=rule_external&apiName=create&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create&project=acs&resource=rule_external&version=v1 document }
*/
create: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/rule_external`, path),
method: "POST",
data,
params,
headers,
paramsSerializer: (params) => qs.stringify(params, { arrayFormat: "repeat" }),
})
.catch((e) => {
this.logger.error(formatErrors(e));
throw e;
});
}),
/**
* {@link https://open.feishu.cn/api-explorer?project=acs&resource=rule_external&apiName=delete&version=v1 click to debug }
*
* {@link https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=delete&project=acs&resource=rule_external&version=v1 document }
*/
delete: (payload, options) => __awaiter(this, void 0, void 0, function* () {
const { headers, params, data, path } = yield this.formatPayload(payload, options);
return this.httpInstance
.request({
url: fillApiPath(`${this.domain}/open-apis/acs/v1/rule_external`, path),