@tego/core 1.3.44

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.
Files changed (152) hide show
  1. package/LICENSE +201 -0
  2. package/lib/acl/available-action.d.ts +5 -0
  3. package/lib/acl/available-action.js +62 -0
  4. package/lib/acl/index.d.ts +2 -0
  5. package/lib/acl/index.js +49 -0
  6. package/lib/aes-encryptor.d.ts +11 -0
  7. package/lib/aes-encryptor.js +116 -0
  8. package/lib/app-command.d.ts +12 -0
  9. package/lib/app-command.js +76 -0
  10. package/lib/app-supervisor.d.ts +61 -0
  11. package/lib/app-supervisor.js +299 -0
  12. package/lib/application.d.ts +354 -0
  13. package/lib/application.js +878 -0
  14. package/lib/cache/index.d.ts +3 -0
  15. package/lib/cache/index.js +35 -0
  16. package/lib/commands/console.d.ts +3 -0
  17. package/lib/commands/console.js +48 -0
  18. package/lib/commands/create-migration.d.ts +3 -0
  19. package/lib/commands/create-migration.js +80 -0
  20. package/lib/commands/db-auth.d.ts +3 -0
  21. package/lib/commands/db-auth.js +28 -0
  22. package/lib/commands/db-clean.d.ts +3 -0
  23. package/lib/commands/db-clean.js +31 -0
  24. package/lib/commands/db-sync.d.ts +3 -0
  25. package/lib/commands/db-sync.js +40 -0
  26. package/lib/commands/destroy.d.ts +3 -0
  27. package/lib/commands/destroy.js +30 -0
  28. package/lib/commands/index.d.ts +2 -0
  29. package/lib/commands/index.js +71 -0
  30. package/lib/commands/install.d.ts +3 -0
  31. package/lib/commands/install.js +33 -0
  32. package/lib/commands/migrator.d.ts +3 -0
  33. package/lib/commands/migrator.js +31 -0
  34. package/lib/commands/pm.d.ts +3 -0
  35. package/lib/commands/pm.js +75 -0
  36. package/lib/commands/refresh.d.ts +3 -0
  37. package/lib/commands/refresh.js +31 -0
  38. package/lib/commands/restart.d.ts +3 -0
  39. package/lib/commands/restart.js +35 -0
  40. package/lib/commands/start.d.ts +3 -0
  41. package/lib/commands/start.js +74 -0
  42. package/lib/commands/stop.d.ts +3 -0
  43. package/lib/commands/stop.js +34 -0
  44. package/lib/commands/upgrade.d.ts +3 -0
  45. package/lib/commands/upgrade.js +29 -0
  46. package/lib/cron/cron-job-manager.d.ts +25 -0
  47. package/lib/cron/cron-job-manager.js +89 -0
  48. package/lib/environment.d.ts +10 -0
  49. package/lib/environment.js +73 -0
  50. package/lib/errors/application-not-install.d.ts +4 -0
  51. package/lib/errors/application-not-install.js +35 -0
  52. package/lib/errors/handler.d.ts +3 -0
  53. package/lib/errors/handler.js +41 -0
  54. package/lib/errors/plugin-command-error.d.ts +2 -0
  55. package/lib/errors/plugin-command-error.js +31 -0
  56. package/lib/errors/plugin-not-exist.d.ts +2 -0
  57. package/lib/errors/plugin-not-exist.js +31 -0
  58. package/lib/gateway/errors.d.ts +22 -0
  59. package/lib/gateway/errors.js +138 -0
  60. package/lib/gateway/gateway.d.ts +56 -0
  61. package/lib/gateway/gateway.js +408 -0
  62. package/lib/gateway/index.d.ts +2 -0
  63. package/lib/gateway/index.js +30 -0
  64. package/lib/gateway/ipc-socket-client.d.ts +17 -0
  65. package/lib/gateway/ipc-socket-client.js +99 -0
  66. package/lib/gateway/ipc-socket-server.d.ts +12 -0
  67. package/lib/gateway/ipc-socket-server.js +140 -0
  68. package/lib/gateway/types.d.ts +25 -0
  69. package/lib/gateway/types.js +15 -0
  70. package/lib/gateway/ws-server.d.ts +63 -0
  71. package/lib/gateway/ws-server.js +335 -0
  72. package/lib/helper.d.ts +11 -0
  73. package/lib/helper.js +193 -0
  74. package/lib/helpers/application-version.d.ts +10 -0
  75. package/lib/helpers/application-version.js +77 -0
  76. package/lib/helpers/multiple-instance-manager.d.ts +6 -0
  77. package/lib/helpers/multiple-instance-manager.js +40 -0
  78. package/lib/index.d.ts +10 -0
  79. package/lib/index.js +57 -0
  80. package/lib/locale/index.d.ts +1 -0
  81. package/lib/locale/index.js +21 -0
  82. package/lib/locale/locale.d.ts +22 -0
  83. package/lib/locale/locale.js +166 -0
  84. package/lib/locale/resource.d.ts +1 -0
  85. package/lib/locale/resource.js +74 -0
  86. package/lib/main-data-source.d.ts +4 -0
  87. package/lib/main-data-source.js +45 -0
  88. package/lib/middlewares/data-template.d.ts +2 -0
  89. package/lib/middlewares/data-template.js +39 -0
  90. package/lib/middlewares/data-wrapping.d.ts +3 -0
  91. package/lib/middlewares/data-wrapping.js +90 -0
  92. package/lib/middlewares/db2resource.d.ts +6 -0
  93. package/lib/middlewares/db2resource.js +76 -0
  94. package/lib/middlewares/extract-client-ip.d.ts +2 -0
  95. package/lib/middlewares/extract-client-ip.js +37 -0
  96. package/lib/middlewares/i18n.d.ts +1 -0
  97. package/lib/middlewares/i18n.js +44 -0
  98. package/lib/middlewares/index.d.ts +3 -0
  99. package/lib/middlewares/index.js +32 -0
  100. package/lib/middlewares/parse-variables.d.ts +1 -0
  101. package/lib/middlewares/parse-variables.js +84 -0
  102. package/lib/migration.d.ts +12 -0
  103. package/lib/migration.js +47 -0
  104. package/lib/migrations/20230912193824-package-name-unique.d.ts +6 -0
  105. package/lib/migrations/20230912193824-package-name-unique.js +52 -0
  106. package/lib/migrations/20230912294620-update-pkg.d.ts +6 -0
  107. package/lib/migrations/20230912294620-update-pkg.js +58 -0
  108. package/lib/migrations/20240106082756-update-plugins.d.ts +6 -0
  109. package/lib/migrations/20240106082756-update-plugins.js +44 -0
  110. package/lib/migrations/20240705000001-remove-pkgs-approval.d.ts +6 -0
  111. package/lib/migrations/20240705000001-remove-pkgs-approval.js +47 -0
  112. package/lib/notice/index.d.ts +25 -0
  113. package/lib/notice/index.js +91 -0
  114. package/lib/plugin-manager/clientStaticUtils.d.ts +24 -0
  115. package/lib/plugin-manager/clientStaticUtils.js +156 -0
  116. package/lib/plugin-manager/constants.d.ts +7 -0
  117. package/lib/plugin-manager/constants.js +120 -0
  118. package/lib/plugin-manager/deps.d.ts +2 -0
  119. package/lib/plugin-manager/deps.js +68 -0
  120. package/lib/plugin-manager/index.d.ts +2 -0
  121. package/lib/plugin-manager/index.js +23 -0
  122. package/lib/plugin-manager/middleware.d.ts +2 -0
  123. package/lib/plugin-manager/middleware.js +36 -0
  124. package/lib/plugin-manager/options/collection.d.ts +2 -0
  125. package/lib/plugin-manager/options/collection.js +39 -0
  126. package/lib/plugin-manager/options/resource.d.ts +15 -0
  127. package/lib/plugin-manager/options/resource.js +185 -0
  128. package/lib/plugin-manager/plugin-manager-repository.d.ts +27 -0
  129. package/lib/plugin-manager/plugin-manager-repository.js +136 -0
  130. package/lib/plugin-manager/plugin-manager.d.ts +205 -0
  131. package/lib/plugin-manager/plugin-manager.js +1032 -0
  132. package/lib/plugin-manager/types.d.ts +15 -0
  133. package/lib/plugin-manager/types.js +15 -0
  134. package/lib/plugin-manager/utils.d.ts +101 -0
  135. package/lib/plugin-manager/utils.js +513 -0
  136. package/lib/plugin-manager/web-service.d.ts +6 -0
  137. package/lib/plugin-manager/web-service.js +116 -0
  138. package/lib/plugin.d.ts +125 -0
  139. package/lib/plugin.js +359 -0
  140. package/lib/pub-sub-manager/handler-manager.d.ts +28 -0
  141. package/lib/pub-sub-manager/handler-manager.js +149 -0
  142. package/lib/pub-sub-manager/index.d.ts +3 -0
  143. package/lib/pub-sub-manager/index.js +25 -0
  144. package/lib/pub-sub-manager/memory-pub-sub-adapter.d.ts +21 -0
  145. package/lib/pub-sub-manager/memory-pub-sub-adapter.js +82 -0
  146. package/lib/pub-sub-manager/pub-sub-manager.d.ts +19 -0
  147. package/lib/pub-sub-manager/pub-sub-manager.js +108 -0
  148. package/lib/pub-sub-manager/types.d.ts +20 -0
  149. package/lib/pub-sub-manager/types.js +15 -0
  150. package/lib/sync-message-manager.d.ts +16 -0
  151. package/lib/sync-message-manager.js +112 -0
  152. package/package.json +58 -0
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.
@@ -0,0 +1,5 @@
1
+ import { AvailableActionOptions } from '@tachybase/acl';
2
+ declare const availableActions: {
3
+ [key: string]: AvailableActionOptions;
4
+ };
5
+ export { availableActions };
@@ -0,0 +1,62 @@
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 available_action_exports = {};
19
+ __export(available_action_exports, {
20
+ availableActions: () => availableActions
21
+ });
22
+ module.exports = __toCommonJS(available_action_exports);
23
+ const availableActions = {
24
+ create: {
25
+ displayName: '{{t("Add new")}}',
26
+ type: "new-data",
27
+ onNewRecord: true,
28
+ aliases: ["create", "firstOrCreate", "updateOrCreate"],
29
+ allowConfigureFields: true
30
+ },
31
+ // import: {
32
+ // displayName: '{{t("Import")}}',
33
+ // type: 'new-data',
34
+ // scope: false,
35
+ // },
36
+ // export: {
37
+ // displayName: '{{t("Export")}}',
38
+ // type: 'old-data',
39
+ // allowConfigureFields: true,
40
+ // },
41
+ view: {
42
+ displayName: '{{t("View")}}',
43
+ type: "old-data",
44
+ aliases: ["get", "list"],
45
+ allowConfigureFields: true
46
+ },
47
+ update: {
48
+ displayName: '{{t("Edit")}}',
49
+ type: "old-data",
50
+ aliases: ["update", "move", "add", "set", "remove", "toggle"],
51
+ allowConfigureFields: true
52
+ },
53
+ destroy: {
54
+ displayName: '{{t("Delete")}}',
55
+ aliases: ["destroy"],
56
+ type: "old-data"
57
+ }
58
+ };
59
+ // Annotate the CommonJS export names for ESM import in node:
60
+ 0 && (module.exports = {
61
+ availableActions
62
+ });
@@ -0,0 +1,2 @@
1
+ import { ACL } from '@tachybase/acl';
2
+ export declare function createACL(): ACL;
@@ -0,0 +1,49 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var acl_exports = {};
20
+ __export(acl_exports, {
21
+ createACL: () => createACL
22
+ });
23
+ module.exports = __toCommonJS(acl_exports);
24
+ var import_acl = require("@tachybase/acl");
25
+ var import_available_action = require("./available-action");
26
+ const configureResources = [
27
+ "roles",
28
+ "users",
29
+ "collections",
30
+ "fields",
31
+ "collections.fields",
32
+ "roles.collections",
33
+ "roles.resources",
34
+ "rolesResourcesScopes",
35
+ "availableActions"
36
+ ];
37
+ function createACL() {
38
+ const acl = new import_acl.ACL();
39
+ for (const [actionName, actionParams] of Object.entries(import_available_action.availableActions)) {
40
+ acl.setAvailableAction(actionName, actionParams);
41
+ }
42
+ acl.registerConfigResources(configureResources);
43
+ return acl;
44
+ }
45
+ __name(createACL, "createACL");
46
+ // Annotate the CommonJS export names for ESM import in node:
47
+ 0 && (module.exports = {
48
+ createACL
49
+ });
@@ -0,0 +1,11 @@
1
+ import Application from './application';
2
+ export declare class AesEncryptor {
3
+ private key;
4
+ constructor(key: Buffer);
5
+ encrypt(text: string): Promise<string>;
6
+ decrypt(encryptedText: string): Promise<string>;
7
+ static getOrGenerateKey(keyFilePath: string): Promise<Buffer>;
8
+ static getKeyPath(appName: string): Promise<string>;
9
+ static create(app: Application): Promise<AesEncryptor>;
10
+ }
11
+ export default AesEncryptor;
@@ -0,0 +1,116 @@
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 __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
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 aes_encryptor_exports = {};
30
+ __export(aes_encryptor_exports, {
31
+ AesEncryptor: () => AesEncryptor,
32
+ default: () => aes_encryptor_default
33
+ });
34
+ module.exports = __toCommonJS(aes_encryptor_exports);
35
+ var import_node_crypto = __toESM(require("node:crypto"));
36
+ var import_node_path = __toESM(require("node:path"));
37
+ var import_fs_extra = __toESM(require("fs-extra"));
38
+ const _AesEncryptor = class _AesEncryptor {
39
+ constructor(key) {
40
+ if (key.length !== 32) {
41
+ throw new Error("Key must be 32 bytes for AES-256 encryption.");
42
+ }
43
+ this.key = key;
44
+ }
45
+ async encrypt(text) {
46
+ return new Promise((resolve, reject) => {
47
+ try {
48
+ const iv = import_node_crypto.default.randomBytes(16);
49
+ const cipher = import_node_crypto.default.createCipheriv("aes-256-cbc", this.key, iv);
50
+ const encrypted = Buffer.concat([cipher.update(Buffer.from(text, "utf8")), cipher.final()]);
51
+ resolve(iv.toString("hex") + encrypted.toString("hex"));
52
+ } catch (error) {
53
+ reject(error);
54
+ }
55
+ });
56
+ }
57
+ async decrypt(encryptedText) {
58
+ return new Promise((resolve, reject) => {
59
+ try {
60
+ const iv = Buffer.from(encryptedText.slice(0, 32), "hex");
61
+ const encrypted = Buffer.from(encryptedText.slice(32), "hex");
62
+ const decipher = import_node_crypto.default.createDecipheriv("aes-256-cbc", this.key, iv);
63
+ const decrypted = Buffer.concat([decipher.update(encrypted), decipher.final()]);
64
+ resolve(decrypted.toString("utf8"));
65
+ } catch (error) {
66
+ reject(error);
67
+ }
68
+ });
69
+ }
70
+ static async getOrGenerateKey(keyFilePath) {
71
+ try {
72
+ const key = await import_fs_extra.default.readFile(keyFilePath);
73
+ if (key.length !== 32) {
74
+ throw new Error("Invalid key length in file.");
75
+ }
76
+ return key;
77
+ } catch (error) {
78
+ if (error.code === "ENOENT") {
79
+ const key = import_node_crypto.default.randomBytes(32);
80
+ await import_fs_extra.default.mkdir(import_node_path.default.dirname(keyFilePath), { recursive: true });
81
+ await import_fs_extra.default.writeFile(keyFilePath, key);
82
+ return key;
83
+ } else {
84
+ throw new Error(`Failed to load key: ${error.message}`);
85
+ }
86
+ }
87
+ }
88
+ static async getKeyPath(appName) {
89
+ const appKeyPath = import_node_path.default.resolve(process.cwd(), "storage", "apps", appName, "aes_key.dat");
90
+ const appKeyExists = await import_fs_extra.default.exists(appKeyPath);
91
+ if (appKeyExists) {
92
+ return appKeyPath;
93
+ }
94
+ const envKeyPath = import_node_path.default.resolve(process.cwd(), "storage", "environment-variables", appName, "aes_key.dat");
95
+ const envKeyExists = await import_fs_extra.default.exists(envKeyPath);
96
+ if (envKeyExists) {
97
+ return envKeyPath;
98
+ }
99
+ return appKeyPath;
100
+ }
101
+ static async create(app) {
102
+ let key = process.env.APP_AES_SECRET_KEY;
103
+ if (!key) {
104
+ const keyPath = await this.getKeyPath(app.name);
105
+ key = await _AesEncryptor.getOrGenerateKey(keyPath);
106
+ }
107
+ return new _AesEncryptor(key);
108
+ }
109
+ };
110
+ __name(_AesEncryptor, "AesEncryptor");
111
+ let AesEncryptor = _AesEncryptor;
112
+ var aes_encryptor_default = AesEncryptor;
113
+ // Annotate the CommonJS export names for ESM import in node:
114
+ 0 && (module.exports = {
115
+ AesEncryptor
116
+ });
@@ -0,0 +1,12 @@
1
+ import { Command } from 'commander';
2
+ export declare class AppCommand extends Command {
3
+ private _handleByIPCServer;
4
+ _preload: boolean;
5
+ ipc(): this;
6
+ auth(): this;
7
+ preload(): this;
8
+ hasCommand(name: string): boolean;
9
+ isHandleByIPCServer(): boolean;
10
+ createCommand(name?: string): AppCommand;
11
+ parseHandleByIPCServer(argv: any, parseOptions?: any): boolean;
12
+ }
@@ -0,0 +1,76 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var app_command_exports = {};
20
+ __export(app_command_exports, {
21
+ AppCommand: () => AppCommand
22
+ });
23
+ module.exports = __toCommonJS(app_command_exports);
24
+ var import_commander = require("commander");
25
+ const _AppCommand = class _AppCommand extends import_commander.Command {
26
+ constructor() {
27
+ super(...arguments);
28
+ this._handleByIPCServer = false;
29
+ this._preload = false;
30
+ }
31
+ ipc() {
32
+ this._handleByIPCServer = true;
33
+ return this;
34
+ }
35
+ auth() {
36
+ this["_authenticate"] = true;
37
+ return this;
38
+ }
39
+ preload() {
40
+ this["_authenticate"] = true;
41
+ this._preload = true;
42
+ return this;
43
+ }
44
+ hasCommand(name) {
45
+ const names = this.commands.map((c) => c.name());
46
+ return names.includes(name);
47
+ }
48
+ isHandleByIPCServer() {
49
+ return this._handleByIPCServer;
50
+ }
51
+ createCommand(name) {
52
+ return new _AppCommand(name);
53
+ }
54
+ parseHandleByIPCServer(argv, parseOptions) {
55
+ const userArgs = this._prepareUserArgs(argv, parseOptions);
56
+ if (userArgs[0] === "tachybase") {
57
+ userArgs.shift();
58
+ }
59
+ let lastCommand = this;
60
+ for (const arg of userArgs) {
61
+ const subCommand = lastCommand._findCommand(arg);
62
+ if (subCommand) {
63
+ lastCommand = subCommand;
64
+ } else {
65
+ break;
66
+ }
67
+ }
68
+ return lastCommand && lastCommand.isHandleByIPCServer();
69
+ }
70
+ };
71
+ __name(_AppCommand, "AppCommand");
72
+ let AppCommand = _AppCommand;
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ AppCommand
76
+ });
@@ -0,0 +1,61 @@
1
+ import { EventEmitter } from 'node:events';
2
+ import { AsyncEmitter } from '@tachybase/utils';
3
+ import Application, { ApplicationOptions } from './application';
4
+ type BootOptions = {
5
+ appName: string;
6
+ options: any;
7
+ appSupervisor: AppSupervisor;
8
+ };
9
+ type AppBootstrapper = (bootOptions: BootOptions) => Promise<void>;
10
+ type AppStatus = 'initializing' | 'initialized' | 'running' | 'commanding' | 'stopped' | 'error' | 'not_found';
11
+ export declare class AppSupervisor extends EventEmitter implements AsyncEmitter {
12
+ private static instance;
13
+ runningMode: 'single' | 'multiple';
14
+ singleAppName: string | null;
15
+ emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
16
+ apps: {
17
+ [appName: string]: Application;
18
+ };
19
+ lastSeenAt: Map<string, number>;
20
+ appErrors: {
21
+ [appName: string]: Error;
22
+ };
23
+ appStatus: {
24
+ [appName: string]: AppStatus;
25
+ };
26
+ lastMaintainingMessage: {
27
+ [appName: string]: string;
28
+ };
29
+ statusBeforeCommanding: {
30
+ [appName: string]: AppStatus;
31
+ };
32
+ private appMutexes;
33
+ private appBootstrapper;
34
+ blockApps: Set<string>;
35
+ private constructor();
36
+ static getInstance(): AppSupervisor;
37
+ setAppError(appName: string, error: Error): void;
38
+ hasAppError(appName: string): boolean;
39
+ clearAppError(appName: string): void;
40
+ reset(): Promise<void>;
41
+ destroy(): Promise<void>;
42
+ setAppStatus(appName: string, status: AppStatus, options?: {}): void;
43
+ touchApp(appName: string): void;
44
+ getMutexOfApp(appName: string): any;
45
+ bootStrapApp(appName: string, options?: {}): Promise<void>;
46
+ getApp(appName: string, options?: {
47
+ withOutBootStrap?: boolean;
48
+ [key: string]: any;
49
+ }): Promise<Application<import("./application").DefaultState, import("./application").DefaultContext>>;
50
+ setAppBootstrapper(appBootstrapper: AppBootstrapper): void;
51
+ getAppStatus(appName: string, defaultStatus?: AppStatus): AppStatus | null;
52
+ bootMainApp(options: ApplicationOptions): Application<import("./application").DefaultState, import("./application").DefaultContext>;
53
+ hasApp(appName: string): boolean;
54
+ addApp(app: Application): Application<import("./application").DefaultState, import("./application").DefaultContext>;
55
+ getAppsNames(): Promise<string[]>;
56
+ removeApp(appName: string): Promise<void>;
57
+ subApps(): Application<import("./application").DefaultState, import("./application").DefaultContext>[];
58
+ on(eventName: string | symbol, listener: (...args: any[]) => void): this;
59
+ private bindAppEvents;
60
+ }
61
+ export {};