@tachybase/plugin-auth-main-app 1.3.18

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [2023-2025] [Tego team]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # @tachybase/plugin-auth-main-app
package/client.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/client';
2
+ export { default } from './dist/client';
package/client.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/client/index.js');
@@ -0,0 +1 @@
1
+ export declare const AuthMainAppManager: () => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,41 @@
1
+ export declare const authMainAppManagerSchema: {
2
+ type: string;
3
+ properties: {
4
+ authMainApp: {
5
+ type: string;
6
+ title: string;
7
+ 'x-decorator': string;
8
+ 'x-component': string;
9
+ 'x-use-component-props': string;
10
+ properties: {
11
+ selfSignIn: {
12
+ type: string;
13
+ title: string;
14
+ 'x-decorator': string;
15
+ 'x-component': string;
16
+ };
17
+ authMainApp: {
18
+ type: string;
19
+ title: string;
20
+ 'x-decorator': string;
21
+ 'x-component': string;
22
+ 'x-hidden': string;
23
+ };
24
+ footer: {
25
+ type: string;
26
+ 'x-component': string;
27
+ properties: {
28
+ submit: {
29
+ title: string;
30
+ 'x-component': string;
31
+ 'x-component-props': {
32
+ type: string;
33
+ useAction: string;
34
+ };
35
+ };
36
+ };
37
+ };
38
+ };
39
+ };
40
+ };
41
+ };
@@ -0,0 +1,3 @@
1
+ export declare const useAuthMainAppValues: () => {
2
+ form: import("@tachybase/schema").Form<any>;
3
+ };
@@ -0,0 +1,3 @@
1
+ export declare const useSaveAuthMainAppValues: () => {
2
+ run(): Promise<void>;
3
+ };
@@ -0,0 +1 @@
1
+ export { default } from './plugin';
@@ -0,0 +1 @@
1
+ (function(t,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@tachybase/client"),require("@tachybase/module-auth/client"),require("react/jsx-runtime"),require("@tachybase/schema"),require("antd"),require("react")):typeof define=="function"&&define.amd?define(["exports","@tachybase/client","@tachybase/module-auth/client","react/jsx-runtime","@tachybase/schema","antd","react"],e):(t=typeof globalThis!="undefined"?globalThis:t||self,e(t["@tachybase/plugin-auth-main-app"]={},t["@tachybase/client"],t["@tachybase/module-auth"],t.jsxRuntime,t["@tachybase/schema"],t.antd,t.react))})(this,function(t,e,i,u,m,l,d){"use strict";var r=(t,e,i)=>new Promise((u,m)=>{var l=a=>{try{h(i.next(a))}catch(s){m(s)}},d=a=>{try{h(i.throw(a))}catch(s){m(s)}},h=a=>a.done?u(a.value):Promise.resolve(a.value).then(l,d);h((i=i.apply(t,e)).next())});const h="auth-main-app",a="authMainAppConfig",s=o=>e.tval(o,{ns:h}),g={type:"object",properties:{authMainApp:{type:"void",title:s("Auth by main app"),"x-decorator":"CardItem","x-component":"FormV2","x-use-component-props":"useAuthMainAppValues",properties:{selfSignIn:{type:"boolean",title:s("Allow the validator of this system to log in."),"x-decorator":"FormItem","x-component":"Checkbox"},authMainApp:{type:"boolean",title:s("Enable Single Sign-On (SSO)"),"x-decorator":"FormItem","x-component":"Checkbox","x-hidden":"{{ isMainApp }}"},footer:{type:"void","x-component":"ActionBar",properties:{submit:{title:'{{t("Submit")}}',"x-component":"Action","x-component-props":{type:"primary",useAction:"{{ useSaveAuthMainAppValues }}"}}}}}}}},S=()=>{const o=e.useAPIClient(),{data:n}=e.useRequest(()=>o.resource(a).get().then(f=>{var y;return(y=f.data)==null?void 0:y.data}));return{form:m.createForm({values:n||{}})}},M=()=>{const o=m.useForm(),n=e.useAPIClient(),{t:c}=e.useTranslation();return{run(){return r(this,null,function*(){yield o.submit(),yield n.request({url:`${a}:set`,method:"post",data:o.values}),l.message.success(c("Saved successfully"))})}}},b=()=>{const n=e.useApp().name==="main";return u.jsx(e.SchemaComponent,{schema:g,scope:{useAuthMainAppValues:S,useSaveAuthMainAppValues:M,isMainApp:n}})},v={type:"object",name:"mainAppForm","x-component":"FormV2",properties:{username:{type:"void","x-component":"div","x-content":"{{ mainUser?.username }}"},phone:{type:"void","x-component":"div","x-content":"{{ mainUser?.phone }}"},actions:{type:"void","x-component":"div",properties:{submit:{title:'{{t("Sign in")}}',type:"void","x-component":"Action","x-component-props":{htmlType:"submit",block:!0,type:"primary",useAction:"{{ useMainAppSignIn }}",style:{width:"100%"}}}}}}},C=o=>{const n=e.useAPIClient(),[c,f]=d.useState(null),y=()=>{const x=e.useAPIClient(),A=i.useRedirect(),{refreshAsync:p}=e.useCurrentUserContext();return{run(){return r(this,null,function*(){x.auth.setToken(c.token),yield p(),A()})}}};return d.useEffect(()=>{r(null,null,function*(){var A;try{const p=yield n.request({method:"post",url:"authMainAppConfig:getMainUser",data:{token:n.auth.getMainToken()}});f((A=p==null?void 0:p.data)==null?void 0:A.data)}catch(p){console.error("Error fetching auth config:",p)}})},[n]),c?u.jsx(e.SchemaComponent,{schema:v,scope:{mainUser:c,useMainAppSignIn:y}}):u.jsx("div",{children:"Loading..."})};class I extends e.Plugin{afterAdd(){return r(this,null,function*(){})}beforeLoad(){return r(this,null,function*(){})}load(){return r(this,null,function*(){if(this.app.name!=="main"){this.app.systemSettingsManager.add("system-services.auth-main-app",{icon:"LoginOutlined",title:s("Single Sign-On (SSO) between applications"),Component:b,aclSnippet:"pm.system-services.auth-main-app"});const n=this.app.pm.get(i);n==null||n.registerType("mainApp",{components:{SignInForm:C}})}})}}t.default=I,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -0,0 +1,6 @@
1
+ export declare function usePluginTranslation(): any;
2
+ export declare function useTranslation(): {
3
+ t: (key: string, options?: {}) => string;
4
+ };
5
+ export declare function lang(key: string, options?: {}): string;
6
+ export declare const tval: (key: string) => string;
@@ -0,0 +1,7 @@
1
+ import { Plugin } from '@tachybase/client';
2
+ declare class PluginAuthMainAppClient extends Plugin {
3
+ afterAdd(): Promise<void>;
4
+ beforeLoad(): Promise<void>;
5
+ load(): Promise<void>;
6
+ }
7
+ export default PluginAuthMainAppClient;
@@ -0,0 +1 @@
1
+ export declare const SignInForm: (props: any) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export declare const NAMESPACE = "auth-main-app";
2
+ export declare const COLLECTION_AUTH_MAIN_APP_CONFIG = "authMainAppConfig";
@@ -0,0 +1,30 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var constants_exports = {};
19
+ __export(constants_exports, {
20
+ COLLECTION_AUTH_MAIN_APP_CONFIG: () => COLLECTION_AUTH_MAIN_APP_CONFIG,
21
+ NAMESPACE: () => NAMESPACE
22
+ });
23
+ module.exports = __toCommonJS(constants_exports);
24
+ const NAMESPACE = "auth-main-app";
25
+ const COLLECTION_AUTH_MAIN_APP_CONFIG = "authMainAppConfig";
26
+ // Annotate the CommonJS export names for ESM import in node:
27
+ 0 && (module.exports = {
28
+ COLLECTION_AUTH_MAIN_APP_CONFIG,
29
+ NAMESPACE
30
+ });
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ "@tachybase/client": "1.3.20",
3
+ "@tachybase/module-auth": "1.3.20",
4
+ "react": "18.3.1",
5
+ "@tachybase/schema": "1.3.20",
6
+ "antd": "5.22.5",
7
+ "@tachybase/server": "1.3.20",
8
+ "@tachybase/actions": "1.3.20",
9
+ "@tachybase/utils": "1.3.20",
10
+ "@tachybase/database": "1.3.20"
11
+ };
@@ -0,0 +1,2 @@
1
+ export * from './server';
2
+ export { default } from './server';
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var index_exports = {};
30
+ __export(index_exports, {
31
+ default: () => import_server.default
32
+ });
33
+ module.exports = __toCommonJS(index_exports);
34
+ __reExport(index_exports, require("./server"), module.exports);
35
+ var import_server = __toESM(require("./server"));
36
+ // Annotate the CommonJS export names for ESM import in node:
37
+ 0 && (module.exports = {
38
+ ...require("./server")
39
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "Single Sign-On (SSO) between applications": "Single Sign-On (SSO) between applications",
3
+ "Unable to disable all authenticators in the main application.": "Unable to disable all authenticators in the main application."
4
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "Allow the validator of this system to log in.": "允许本系统验证器登录",
3
+ "Auth by main app": "通过主应用登录",
4
+ "Can not manage this sub app!": "没有权限管理此应用",
5
+ "Enable Single Sign-On (SSO)": "允许统一登录(SSO)",
6
+ "Failed to fetch authentication information. Please try again.": "获取认证信息失败。请再试一次。",
7
+ "It is impossible to delete all login verification methods.": "无法删除所有登录验证方式",
8
+ "Main app signIn": "主应用登录",
9
+ "Please log in to the main application first": "请先登录主应用",
10
+ "Single Sign-On (SSO) between applications": "跨应用的单点登录(SSO)",
11
+ "Unable to disable all authenticators in the main application.": "无法在主应用禁用所有认证器",
12
+ "Unable to manage this application, please exit the main application and change to a new account": "无法管理此应用,请在主应用退出换一个账号"
13
+ }
@@ -0,0 +1,6 @@
1
+ import { Context } from '@tachybase/actions';
2
+ export declare class AuthMainAppController {
3
+ getMainUser(ctx: Context, next: () => Promise<any>): Promise<any>;
4
+ get(ctx: Context, next: () => Promise<any>): Promise<any>;
5
+ set(ctx: Context, next: () => Promise<any>): Promise<any>;
6
+ }
@@ -0,0 +1,185 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
26
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
27
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
28
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
29
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
30
+ var __runInitializers = (array, flags, self, value) => {
31
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
32
+ return value;
33
+ };
34
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
35
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
36
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
37
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
38
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
39
+ return __privateGet(this, extra);
40
+ }, set [name](x) {
41
+ return __privateSet(this, extra, x);
42
+ } }, name));
43
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
44
+ for (var i = decorators.length - 1; i >= 0; i--) {
45
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
46
+ if (k) {
47
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
48
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
49
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
50
+ }
51
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
52
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
53
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
54
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
55
+ }
56
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
57
+ };
58
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
59
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
60
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
61
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
62
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
63
+ var authMainApp_exports = {};
64
+ __export(authMainApp_exports, {
65
+ AuthMainAppController: () => AuthMainAppController
66
+ });
67
+ module.exports = __toCommonJS(authMainApp_exports);
68
+ var import_server = require("@tachybase/server");
69
+ var import_utils = require("@tachybase/utils");
70
+ var import_constants = require("../../constants");
71
+ var _set_dec, _get_dec, _getMainUser_dec, _AuthMainAppController_decorators, _init;
72
+ _AuthMainAppController_decorators = [(0, import_utils.Controller)("authMainAppConfig")], _getMainUser_dec = [(0, import_utils.Action)("getMainUser", { acl: "public" })], _get_dec = [(0, import_utils.Action)("get", { acl: "public" })], _set_dec = [(0, import_utils.Action)("set", { acl: "public" })];
73
+ class AuthMainAppController {
74
+ constructor() {
75
+ __runInitializers(_init, 5, this);
76
+ }
77
+ async getMainUser(ctx, next) {
78
+ if (ctx.app.name === "main") {
79
+ ctx.body = {};
80
+ return next();
81
+ }
82
+ const { token } = ctx.action.params.values;
83
+ const mainApp = await import_server.AppSupervisor.getInstance().getApp("main");
84
+ const jwt = mainApp.authManager.jwt;
85
+ let user;
86
+ try {
87
+ user = await jwt.decode(token);
88
+ } catch (err) {
89
+ ctx.throw(401, ctx.t("Please log in to the main application first", { ns: import_constants.NAMESPACE }));
90
+ }
91
+ const multiAppRepo = mainApp.db.getRepository("applications");
92
+ const multiApp = await multiAppRepo.findOne({
93
+ filter: {
94
+ name: ctx.app.name,
95
+ createdById: user.userId
96
+ }
97
+ });
98
+ if (!multiApp) {
99
+ ctx.throw(
100
+ 403,
101
+ ctx.t("Unable to manage this application, please exit the main application and change to a new account", {
102
+ ns: import_constants.NAMESPACE
103
+ })
104
+ );
105
+ }
106
+ const repo = ctx.db.getRepository("users");
107
+ const root = await repo.findOne({
108
+ filter: {
109
+ specialRole: "root"
110
+ }
111
+ });
112
+ const tokenInfo = await mainApp.authManager.tokenController.add({ userId: root.id });
113
+ const expiresIn = Math.floor((await mainApp.authManager.tokenController.getConfig()).tokenExpirationTime / 1e3);
114
+ const newToken = ctx.app.authManager.jwt.sign(
115
+ {
116
+ userId: root.id,
117
+ temp: true,
118
+ iat: Math.floor(tokenInfo.issuedTime / 1e3),
119
+ signInTime: tokenInfo.signInTime
120
+ },
121
+ {
122
+ jwtid: tokenInfo.jti,
123
+ expiresIn
124
+ }
125
+ );
126
+ const mainUserRepo = mainApp.db.getRepository("users");
127
+ const userInfo = await mainUserRepo.findOne({
128
+ fields: ["username", "nickname", "phone"],
129
+ filter: {
130
+ id: user.userId
131
+ },
132
+ raw: true
133
+ });
134
+ ctx.body = {
135
+ ...userInfo,
136
+ token: newToken
137
+ };
138
+ return next();
139
+ }
140
+ async get(ctx, next) {
141
+ const repo = ctx.db.getRepository(import_constants.COLLECTION_AUTH_MAIN_APP_CONFIG);
142
+ const existOne = await repo.findOne();
143
+ ctx.body = existOne;
144
+ return next();
145
+ }
146
+ async set(ctx, next) {
147
+ const { selfSignIn, authMainApp } = ctx.action.params.values;
148
+ if (ctx.app.name === "main" && !selfSignIn) {
149
+ ctx.throw(400, ctx.t("Unable to disable all authenticators in the main application.", { ns: import_constants.NAMESPACE }));
150
+ }
151
+ if (!selfSignIn && !authMainApp) {
152
+ ctx.throw(400, ctx.t("It is impossible to delete all login verification methods.", { ns: import_constants.NAMESPACE }));
153
+ }
154
+ const repo = ctx.db.getRepository(import_constants.COLLECTION_AUTH_MAIN_APP_CONFIG);
155
+ const existOne = await repo.findOne();
156
+ if (!existOne) {
157
+ await repo.create({
158
+ values: {
159
+ selfSignIn,
160
+ authMainApp
161
+ }
162
+ });
163
+ } else {
164
+ await repo.update({
165
+ filterByTk: existOne.id,
166
+ values: {
167
+ selfSignIn,
168
+ authMainApp
169
+ }
170
+ });
171
+ }
172
+ ctx.body = "ok";
173
+ return next();
174
+ }
175
+ }
176
+ _init = __decoratorStart(null);
177
+ __decorateElement(_init, 1, "getMainUser", _getMainUser_dec, AuthMainAppController);
178
+ __decorateElement(_init, 1, "get", _get_dec, AuthMainAppController);
179
+ __decorateElement(_init, 1, "set", _set_dec, AuthMainAppController);
180
+ AuthMainAppController = __decorateElement(_init, 0, "AuthMainAppController", _AuthMainAppController_decorators, AuthMainAppController);
181
+ __runInitializers(_init, 1, AuthMainAppController);
182
+ // Annotate the CommonJS export names for ESM import in node:
183
+ 0 && (module.exports = {
184
+ AuthMainAppController
185
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: import("@tachybase/database").CollectionOptions;
2
+ export default _default;
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var authMainAppConfig_exports = {};
19
+ __export(authMainAppConfig_exports, {
20
+ default: () => authMainAppConfig_default
21
+ });
22
+ module.exports = __toCommonJS(authMainAppConfig_exports);
23
+ var import_database = require("@tachybase/database");
24
+ var import_constants = require("../../constants");
25
+ var authMainAppConfig_default = (0, import_database.defineCollection)({
26
+ dumpRules: "required",
27
+ name: import_constants.COLLECTION_AUTH_MAIN_APP_CONFIG,
28
+ updatedAt: true,
29
+ createdAt: true,
30
+ autoGenId: true,
31
+ fields: [
32
+ {
33
+ type: "boolean",
34
+ name: "selfSignIn",
35
+ // 关闭本应用所有认证器
36
+ defaultValue: false
37
+ },
38
+ {
39
+ type: "boolean",
40
+ name: "authMainApp",
41
+ // 是否支持从主应用一键登录
42
+ defaultValue: true
43
+ }
44
+ ]
45
+ });
@@ -0,0 +1 @@
1
+ export { default } from './plugin';
@@ -0,0 +1,33 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var server_exports = {};
29
+ __export(server_exports, {
30
+ default: () => import_plugin.default
31
+ });
32
+ module.exports = __toCommonJS(server_exports);
33
+ var import_plugin = __toESM(require("./plugin"));
@@ -0,0 +1,11 @@
1
+ import { Plugin } from '@tachybase/server';
2
+ export declare class PluginAuthMainAppServer extends Plugin {
3
+ afterAdd(): Promise<void>;
4
+ beforeLoad(): Promise<void>;
5
+ load(): Promise<void>;
6
+ install(): Promise<void>;
7
+ afterEnable(): Promise<void>;
8
+ afterDisable(): Promise<void>;
9
+ remove(): Promise<void>;
10
+ }
11
+ export default PluginAuthMainAppServer;
@@ -0,0 +1,100 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
26
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
27
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
28
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
29
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
30
+ var __runInitializers = (array, flags, self, value) => {
31
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
32
+ return value;
33
+ };
34
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
35
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
36
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
37
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
38
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
39
+ return __privateGet(this, extra);
40
+ }, set [name](x) {
41
+ return __privateSet(this, extra, x);
42
+ } }, name));
43
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
44
+ for (var i = decorators.length - 1; i >= 0; i--) {
45
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
46
+ if (k) {
47
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
48
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
49
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
50
+ }
51
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
52
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
53
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
54
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
55
+ }
56
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
57
+ };
58
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
59
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
60
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
61
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
62
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
63
+ var plugin_exports = {};
64
+ __export(plugin_exports, {
65
+ PluginAuthMainAppServer: () => PluginAuthMainAppServer,
66
+ default: () => plugin_default
67
+ });
68
+ module.exports = __toCommonJS(plugin_exports);
69
+ var import_server = require("@tachybase/server");
70
+ var import_authMainApp = require("./actions/authMainApp");
71
+ var import_authMainAppService = require("./service/authMainAppService");
72
+ var _PluginAuthMainAppServer_decorators, _init, _a;
73
+ _PluginAuthMainAppServer_decorators = [(0, import_server.InjectedPlugin)({
74
+ Controllers: [import_authMainApp.AuthMainAppController],
75
+ Services: [import_authMainAppService.AuthMainAppService]
76
+ })];
77
+ class PluginAuthMainAppServer extends (_a = import_server.Plugin) {
78
+ async afterAdd() {
79
+ }
80
+ async beforeLoad() {
81
+ }
82
+ async load() {
83
+ }
84
+ async install() {
85
+ }
86
+ async afterEnable() {
87
+ }
88
+ async afterDisable() {
89
+ }
90
+ async remove() {
91
+ }
92
+ }
93
+ _init = __decoratorStart(_a);
94
+ PluginAuthMainAppServer = __decorateElement(_init, 0, "PluginAuthMainAppServer", _PluginAuthMainAppServer_decorators, PluginAuthMainAppServer);
95
+ __runInitializers(_init, 1, PluginAuthMainAppServer);
96
+ var plugin_default = PluginAuthMainAppServer;
97
+ // Annotate the CommonJS export names for ESM import in node:
98
+ 0 && (module.exports = {
99
+ PluginAuthMainAppServer
100
+ });
@@ -0,0 +1,12 @@
1
+ import Database from '@tachybase/database';
2
+ import { Application } from '@tachybase/server';
3
+ export declare class AuthMainAppService {
4
+ db: Database;
5
+ app: Application;
6
+ private logger;
7
+ private selfSignIn;
8
+ private authMainApp;
9
+ load(): Promise<void>;
10
+ checkInstall(): Promise<void>;
11
+ addMiddleWare(): void;
12
+ }
@@ -0,0 +1,149 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
7
+ var __typeError = (msg) => {
8
+ throw TypeError(msg);
9
+ };
10
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
11
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
12
+ var __export = (target, all) => {
13
+ for (var name in all)
14
+ __defProp(target, name, { get: all[name], enumerable: true });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from))
19
+ if (!__hasOwnProp.call(to, key) && key !== except)
20
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21
+ }
22
+ return to;
23
+ };
24
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
25
+ var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
26
+ var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
27
+ var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
28
+ var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
29
+ var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
30
+ var __runInitializers = (array, flags, self, value) => {
31
+ for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
32
+ return value;
33
+ };
34
+ var __decorateElement = (array, flags, name, decorators, target, extra) => {
35
+ var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
36
+ var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
37
+ var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
38
+ var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
39
+ return __privateGet(this, extra);
40
+ }, set [name](x) {
41
+ return __privateSet(this, extra, x);
42
+ } }, name));
43
+ k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
44
+ for (var i = decorators.length - 1; i >= 0; i--) {
45
+ ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
46
+ if (k) {
47
+ ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
48
+ if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
49
+ if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
50
+ }
51
+ it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
52
+ if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
53
+ else if (typeof it !== "object" || it === null) __typeError("Object expected");
54
+ else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
55
+ }
56
+ return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
57
+ };
58
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
59
+ var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
60
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
61
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
62
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
63
+ var authMainAppService_exports = {};
64
+ __export(authMainAppService_exports, {
65
+ AuthMainAppService: () => AuthMainAppService
66
+ });
67
+ module.exports = __toCommonJS(authMainAppService_exports);
68
+ var import_utils = require("@tachybase/utils");
69
+ var import_constants = require("../../constants");
70
+ var _logger_dec, _app_dec, _db_dec, _AuthMainAppService_decorators, _init;
71
+ _AuthMainAppService_decorators = [(0, import_utils.Service)()], _db_dec = [(0, import_utils.Db)()], _app_dec = [(0, import_utils.App)()], _logger_dec = [(0, import_utils.InjectLog)()];
72
+ class AuthMainAppService {
73
+ constructor() {
74
+ this.db = __runInitializers(_init, 8, this), __runInitializers(_init, 11, this);
75
+ this.app = __runInitializers(_init, 12, this), __runInitializers(_init, 15, this);
76
+ this.logger = __runInitializers(_init, 16, this), __runInitializers(_init, 19, this);
77
+ this.selfSignIn = true;
78
+ //子应用本身登录
79
+ this.authMainApp = true;
80
+ }
81
+ //通过主应用登录
82
+ async load() {
83
+ this.addMiddleWare();
84
+ this.app.on("afterStart", async () => {
85
+ await this.checkInstall();
86
+ const config = await this.db.getRepository(import_constants.COLLECTION_AUTH_MAIN_APP_CONFIG).findOne();
87
+ if (config) {
88
+ this.selfSignIn = config.selfSignIn ?? true;
89
+ this.authMainApp = config.authMainApp ?? true;
90
+ }
91
+ });
92
+ this.db.on(`${import_constants.COLLECTION_AUTH_MAIN_APP_CONFIG}.afterSave`, (model) => {
93
+ this.selfSignIn = model.get("selfSignIn");
94
+ this.authMainApp = model.get("authMainApp");
95
+ });
96
+ }
97
+ async checkInstall() {
98
+ const repo = this.db.getRepository(import_constants.COLLECTION_AUTH_MAIN_APP_CONFIG);
99
+ const existOne = await repo.findOne();
100
+ if (!existOne) {
101
+ await repo.create({
102
+ values: {
103
+ selfSignIn: true,
104
+ authMainApp: true
105
+ }
106
+ });
107
+ }
108
+ }
109
+ addMiddleWare() {
110
+ this.app.resourcer.use(
111
+ async (ctx, next) => {
112
+ if (ctx.app.name === "main") {
113
+ return next();
114
+ }
115
+ const { resourceName, actionName } = ctx.action.params;
116
+ await next();
117
+ if (resourceName === "authenticators" && actionName === "publicList") {
118
+ if (!this.selfSignIn && !this.authMainApp) {
119
+ return;
120
+ }
121
+ if (!this.selfSignIn) {
122
+ ctx.body = [];
123
+ }
124
+ if (this.authMainApp) {
125
+ ctx.body.unshift({
126
+ name: ctx.t("Main app signIn", { ns: import_constants.NAMESPACE }),
127
+ authType: "mainApp",
128
+ authTypeTitle: "main app"
129
+ });
130
+ }
131
+ }
132
+ },
133
+ {
134
+ tag: "forbidSignIn",
135
+ after: "acl"
136
+ }
137
+ );
138
+ }
139
+ }
140
+ _init = __decoratorStart(null);
141
+ __decorateElement(_init, 5, "db", _db_dec, AuthMainAppService);
142
+ __decorateElement(_init, 5, "app", _app_dec, AuthMainAppService);
143
+ __decorateElement(_init, 5, "logger", _logger_dec, AuthMainAppService);
144
+ AuthMainAppService = __decorateElement(_init, 0, "AuthMainAppService", _AuthMainAppService_decorators, AuthMainAppService);
145
+ __runInitializers(_init, 1, AuthMainAppService);
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ AuthMainAppService
149
+ });
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@tachybase/plugin-auth-main-app",
3
+ "displayName": "Single Sign-On on multi app (SSO)",
4
+ "version": "1.3.18",
5
+ "description": "Users log in via the main application; sub-applications can disable their standalone login.",
6
+ "keywords": [
7
+ "Authentication"
8
+ ],
9
+ "main": "dist/server/index.js",
10
+ "devDependencies": {
11
+ "antd": "5.22.5"
12
+ },
13
+ "peerDependencies": {
14
+ "@tachybase/auth": "1.3.20",
15
+ "@tachybase/actions": "1.3.20",
16
+ "@tachybase/database": "1.3.20",
17
+ "@tachybase/client": "1.3.20",
18
+ "@tachybase/module-auth": "1.3.20",
19
+ "@tachybase/schema": "1.3.20",
20
+ "@tachybase/server": "1.3.20",
21
+ "@tachybase/test": "1.3.20",
22
+ "@tachybase/utils": "1.3.20"
23
+ },
24
+ "description.zh-CN": "通过主应用登录子应用,子应用可关闭登录",
25
+ "displayName.zh-CN": "多应用统一登录"
26
+ }
package/server.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export * from './dist/server';
2
+ export { default } from './dist/server';
package/server.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/server/index.js');