UNPKG

@etsoo/smarterp-core

Version:

TypeScript APIs for SmartERP Core

195 lines (194 loc) 5.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoreApp = void 0; const MemberApi_1 = require("./MemberApi"); const OrgApi_1 = require("./OrgApi"); const AppApi_1 = require("./AppApi"); const PublicApi_1 = require("./PublicApi"); const UserApi_1 = require("./UserApi"); const appscript_1 = require("@etsoo/appscript"); const AuthCodeApi_1 = require("./AuthCodeApi"); const shared_1 = require("@etsoo/shared"); const CoreApiService_1 = require("./dto/org/CoreApiService"); /** * Core application * 核心应用程序 */ class CoreApp { app; api; _appApi; /** * Application API * 应用程序接口 */ get appApi() { return (this._appApi ??= new AppApi_1.AppApi(this.app, this.api)); } _authApi; /** * Authentication API * 认证接口 */ get authApi() { return (this._authApi ??= new appscript_1.AuthApi(this.app, this.api)); } _authCodeApi; /** * Authentication API * 认证接口 */ get authCodeApi() { return (this._authCodeApi ??= new AuthCodeApi_1.AuthCodeApi(this.app, this.api)); } _memberApi; /** * Member API * 会员接口 */ get memberApi() { return (this._memberApi ??= new MemberApi_1.MemberApi(this.app, this.api)); } _orgApi; /** * Organization API * 机构接口 */ get orgApi() { return (this._orgApi ??= new OrgApi_1.OrgApi(this.app, this.api)); } _publicApi; /** * Public API * 公共接口 */ get publicApi() { return (this._publicApi ??= new PublicApi_1.PublicApi(this.app, this.api)); } _userApi; /** * User API * 用户接口 */ get userApi() { return (this._userApi ??= new UserApi_1.UserApi(this.app, this.api)); } /** * Constructor * 构造函数 * @param app Base application * @param api API */ constructor(app, api) { this.app = app; this.api = api; } /** * Get API service label * 获取API服务标签 * @param service API service * @returns Result */ getApiService(service) { if (service == null) return ""; const key = shared_1.DataTypes.getEnumKey(CoreApiService_1.CoreApiService, service) ?? `${service}`; return this.app.get(`apiService${key}`) ?? key; } /** * Get API services * 获取API服务列表 * @returns List of API services */ getApiServices() { return this.app.getEnumList(CoreApiService_1.CoreApiService, "apiService"); } /** * Get app name * 获取应用名称 * @param data App data * @returns Name */ getAppName(data) { return (data.localName ?? this.app.get(`app${data.appId ?? data.id}`) ?? data.name); } /** * Get user identifier type label * 获取用户标识类型标签 * @param type Type * @returns Label */ getIdentifierTypeLabel(type) { const key = shared_1.DataTypes.getEnumKey(appscript_1.UserIdentifierType, type) ?? `${type}`; return this.app.get(`uiType${key}`) ?? key; } /** * Get identity label * 获取身份标签 * @param identity Identity value * @param joinChar Join character * @returns Label(s) */ getIdentityLabel(identity, joinChar) { if (identity == null) return ""; joinChar ??= ", "; const identities = this.getIdentities(identity); return identities.map((r) => r.label).join(joinChar); } /** * Get identity flags label * 获取身份组合标签 * @param identity Identity value * @param joinChar Join character * @returns Label(s) */ getIdentityFlagsLabel(identity, joinChar) { if (identity == null) return ""; joinChar ??= ", "; const identities = this.getIdentityFlags(identity); return identities .filter((r) => r.id > 0) .map((r) => r.label) .join(joinChar); } /** * Get identities * 获取身份列表 * @param identity Identity value combined * @returns List */ getIdentities(identity) { if (identity == null) return this.app.getEnumList(appscript_1.IdentityType, "id"); return this.app.getEnumList(appscript_1.IdentityType, "id", (id, _key) => { if ((id & identity) > 0) return id; }); } /** * Get identity flags * 获取身份标志组合 * @param identity Identity value combined or true for items other than None * @returns List */ getIdentityFlags(identity) { if (identity == null) return this.app.getEnumList(appscript_1.IdentityTypeFlags, "id"); if (identity === true) { return this.app.getEnumList(appscript_1.IdentityTypeFlags, "id", (id, _key) => { if (id > 0) return id; }); } if (identity === 0) return []; // When identity exists, includes the None item return this.app.getEnumList(appscript_1.IdentityTypeFlags, "id", (id, _key) => { if (id === 0 || (id & identity) > 0) return id; }); } } exports.CoreApp = CoreApp;